2016-12-30 02:07:42 +01:00
|
|
|
<?php
|
|
|
|
namespace Psalm\Config;
|
|
|
|
|
2017-01-16 17:41:57 +01:00
|
|
|
use Psalm\Config;
|
2016-12-30 02:07:42 +01:00
|
|
|
use SimpleXMLElement;
|
|
|
|
|
|
|
|
class IssueHandler
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
2017-02-12 00:56:38 +01:00
|
|
|
private $error_level = \Psalm\Config::REPORT_ERROR;
|
2016-12-30 02:07:42 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array<ErrorLevelFileFilter>
|
|
|
|
*/
|
2017-02-12 00:56:38 +01:00
|
|
|
private $custom_levels = [];
|
2016-12-30 02:07:42 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param SimpleXMLElement $e
|
|
|
|
* @return self
|
|
|
|
*/
|
2017-02-12 01:30:06 +01:00
|
|
|
public static function loadFromXMLElement(SimpleXMLElement $e)
|
2016-12-30 02:07:42 +01:00
|
|
|
{
|
|
|
|
$handler = new self();
|
|
|
|
|
|
|
|
if (isset($e['errorLevel'])) {
|
|
|
|
$handler->error_level = (string) $e['errorLevel'];
|
|
|
|
|
|
|
|
if (!in_array($handler->error_level, \Psalm\Config::$ERROR_LEVELS)) {
|
|
|
|
throw new \Psalm\Exception\ConfigException('Unexepected error level ' . $handler->error_level);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @var \SimpleXMLElement $error_level */
|
|
|
|
foreach ($e->errorLevel as $error_level) {
|
2017-02-12 01:30:06 +01:00
|
|
|
$handler->custom_levels[] = ErrorLevelFileFilter::loadFromXMLElement($error_level, true);
|
2016-12-30 02:07:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return $handler;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $error_level
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function setErrorLevel($error_level)
|
|
|
|
{
|
|
|
|
if (!in_array($error_level, \Psalm\Config::$ERROR_LEVELS)) {
|
|
|
|
throw new \Psalm\Exception\ConfigException('Unexepected error level ' . $error_level);
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->error_level = $error_level;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-01-16 18:59:09 +01:00
|
|
|
* @param string $file_path
|
2016-12-30 02:07:42 +01:00
|
|
|
* @return string
|
|
|
|
*/
|
2017-01-16 18:59:09 +01:00
|
|
|
public function getReportingLevelForFile($file_path)
|
2016-12-30 02:07:42 +01:00
|
|
|
{
|
|
|
|
foreach ($this->custom_levels as $custom_level) {
|
2017-01-16 18:59:09 +01:00
|
|
|
if ($custom_level->allows($file_path)) {
|
2016-12-30 02:07:42 +01:00
|
|
|
return $custom_level->getErrorLevel();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->error_level;
|
|
|
|
}
|
|
|
|
}
|