2015-10-15 11:07:54 +02:00
|
|
|
<?php
|
|
|
|
|
2016-07-19 20:28:11 +02:00
|
|
|
namespace PHPCensor\Model;
|
2015-10-15 11:07:54 +02:00
|
|
|
|
2018-03-09 19:00:53 +01:00
|
|
|
use PHPCensor\Model\Base\BuildError as BaseBuildError;
|
|
|
|
use PHPCensor\Store\BuildStore;
|
2018-03-04 08:30:34 +01:00
|
|
|
use PHPCensor\Store\Factory;
|
2015-10-15 11:07:54 +02:00
|
|
|
|
2018-03-09 19:00:53 +01:00
|
|
|
class BuildError extends BaseBuildError
|
2015-10-15 11:07:54 +02:00
|
|
|
{
|
2017-10-15 16:58:36 +02:00
|
|
|
const SEVERITY_CRITICAL = 0;
|
2017-10-19 17:05:00 +02:00
|
|
|
const SEVERITY_HIGH = 1;
|
|
|
|
const SEVERITY_NORMAL = 2;
|
|
|
|
const SEVERITY_LOW = 3;
|
2017-10-15 16:58:36 +02:00
|
|
|
|
2017-02-16 13:45:50 +01:00
|
|
|
/**
|
2018-03-09 19:00:53 +01:00
|
|
|
* @return Build|null
|
2017-02-16 13:45:50 +01:00
|
|
|
*/
|
|
|
|
public function getBuild()
|
|
|
|
{
|
2018-03-03 18:27:48 +01:00
|
|
|
$buildId = $this->getBuildId();
|
|
|
|
if (empty($buildId)) {
|
2017-02-16 13:45:50 +01:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2018-03-09 19:00:53 +01:00
|
|
|
/** @var BuildStore $buildStore */
|
|
|
|
$buildStore = Factory::getStore('Build');
|
|
|
|
|
|
|
|
return $buildStore->getById($buildId);
|
2017-02-16 13:45:50 +01:00
|
|
|
}
|
|
|
|
|
2015-10-15 11:17:22 +02:00
|
|
|
/**
|
|
|
|
* Get the language string key for this error's severity level.
|
2017-10-15 16:58:36 +02:00
|
|
|
*
|
2015-10-15 11:17:22 +02:00
|
|
|
* @return string
|
|
|
|
*/
|
2015-10-15 11:07:54 +02:00
|
|
|
public function getSeverityString()
|
|
|
|
{
|
|
|
|
switch ($this->getSeverity()) {
|
|
|
|
case self::SEVERITY_CRITICAL:
|
|
|
|
return 'critical';
|
|
|
|
|
|
|
|
case self::SEVERITY_HIGH:
|
|
|
|
return 'high';
|
|
|
|
|
|
|
|
case self::SEVERITY_NORMAL:
|
|
|
|
return 'normal';
|
|
|
|
|
|
|
|
case self::SEVERITY_LOW:
|
|
|
|
return 'low';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-29 15:26:43 +01:00
|
|
|
/**
|
|
|
|
* Get the language string key for this error's severity level.
|
|
|
|
*
|
|
|
|
* @param integer $severity
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function getSeverityName($severity)
|
|
|
|
{
|
|
|
|
switch ($severity) {
|
|
|
|
case self::SEVERITY_CRITICAL:
|
|
|
|
return 'critical';
|
|
|
|
|
|
|
|
case self::SEVERITY_HIGH:
|
|
|
|
return 'high';
|
|
|
|
|
|
|
|
case self::SEVERITY_NORMAL:
|
|
|
|
return 'normal';
|
|
|
|
|
|
|
|
case self::SEVERITY_LOW:
|
|
|
|
return 'low';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-09 16:04:34 +01:00
|
|
|
/**
|
|
|
|
* @param string $plugin
|
|
|
|
* @param string $file
|
|
|
|
* @param integer $lineStart
|
|
|
|
* @param integer $lineEnd
|
|
|
|
* @param integer $severity
|
|
|
|
* @param string $message
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function generateHash($plugin, $file, $lineStart, $lineEnd, $severity, $message)
|
|
|
|
{
|
|
|
|
return md5($plugin . $file . $lineStart . $lineEnd . $severity . $message);
|
|
|
|
}
|
|
|
|
|
2015-10-15 11:17:22 +02:00
|
|
|
/**
|
|
|
|
* Get the class to apply to HTML elements representing this error.
|
2017-10-15 16:58:36 +02:00
|
|
|
*
|
2015-10-15 11:17:22 +02:00
|
|
|
* @return string
|
|
|
|
*/
|
2015-10-15 11:07:54 +02:00
|
|
|
public function getSeverityClass()
|
|
|
|
{
|
|
|
|
switch ($this->getSeverity()) {
|
|
|
|
case self::SEVERITY_CRITICAL:
|
|
|
|
return 'danger';
|
|
|
|
|
|
|
|
case self::SEVERITY_HIGH:
|
|
|
|
return 'warning';
|
|
|
|
|
|
|
|
case self::SEVERITY_NORMAL:
|
|
|
|
return 'info';
|
|
|
|
|
|
|
|
case self::SEVERITY_LOW:
|
|
|
|
return 'default';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|