php-censor/src/Model/BuildError.php

115 lines
2.6 KiB
PHP
Raw Normal View History

<?php
2016-07-19 20:28:11 +02:00
namespace PHPCensor\Model;
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;
2018-03-09 19:00:53 +01:00
class BuildError extends BaseBuildError
{
const SEVERITY_CRITICAL = 0;
const SEVERITY_HIGH = 1;
const SEVERITY_NORMAL = 2;
const SEVERITY_LOW = 3;
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.
*
2015-10-15 11:17:22 +02:00
* @return string
*/
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';
}
}
/**
* 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';
}
}
/**
* @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.
*
2015-10-15 11:17:22 +02:00
* @return string
*/
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';
}
}
}