2016-06-06 02:25:16 +02:00
|
|
|
<?php
|
|
|
|
|
2016-07-26 00:37:44 +02:00
|
|
|
namespace Psalm;
|
2016-06-06 02:25:16 +02:00
|
|
|
|
2016-06-26 21:18:40 +02:00
|
|
|
class IssueBuffer
|
2016-06-06 02:25:16 +02:00
|
|
|
{
|
2016-06-21 01:30:38 +02:00
|
|
|
protected static $errors = [];
|
|
|
|
|
2016-07-22 19:29:46 +02:00
|
|
|
public static function accepts(Issue\CodeIssue $e, array $suppressed_issues = [])
|
2016-06-06 02:25:16 +02:00
|
|
|
{
|
2016-06-10 00:08:25 +02:00
|
|
|
$config = Config::getInstance();
|
|
|
|
|
2016-07-26 21:00:40 +02:00
|
|
|
$fqcn_parts = explode('\\', get_class($e));
|
|
|
|
$issue_type = array_pop($fqcn_parts);
|
2016-07-22 19:29:46 +02:00
|
|
|
|
|
|
|
if (in_array($issue_type, $suppressed_issues)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($config->excludeIssueInFile($issue_type, $e->getFileName())) {
|
2016-06-10 00:08:25 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-06-27 19:22:16 +02:00
|
|
|
self::add($e);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function add(Issue\CodeIssue $e)
|
|
|
|
{
|
|
|
|
$config = Config::getInstance();
|
|
|
|
|
2016-07-26 21:00:40 +02:00
|
|
|
$fqcn_parts = explode('\\', get_class($e));
|
|
|
|
$issue_type = array_pop($fqcn_parts);
|
2016-06-17 23:34:52 +02:00
|
|
|
|
2016-07-26 21:00:40 +02:00
|
|
|
$error_message = $issue_type . ' - ' . $e->getMessage();
|
2016-07-22 19:29:46 +02:00
|
|
|
|
|
|
|
$reporting_level = $config->getReportingLevel($issue_type);
|
2016-06-27 04:03:37 +02:00
|
|
|
|
|
|
|
switch ($reporting_level) {
|
|
|
|
case Config::REPORT_INFO:
|
|
|
|
echo 'INFO: ' . $error_message . PHP_EOL;
|
|
|
|
return false;
|
|
|
|
|
|
|
|
case Config::REPORT_SUPPRESS:
|
|
|
|
return false;
|
2016-06-10 20:47:44 +02:00
|
|
|
}
|
|
|
|
|
2016-06-27 04:40:57 +02:00
|
|
|
if ($config->throw_exception) {
|
|
|
|
throw new Exception\CodeException($error_message);
|
|
|
|
}
|
|
|
|
|
2016-07-25 21:05:58 +02:00
|
|
|
echo (ProjectChecker::$use_color ? "\033[0;31m" : '') . 'ERROR: ' . (ProjectChecker::$use_color ? "\033[0m" : '') . $error_message . PHP_EOL;
|
2016-06-17 01:02:29 +02:00
|
|
|
|
2016-06-21 01:30:38 +02:00
|
|
|
if ($config->stop_on_first_error) {
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
self::$errors[] = $error_message;
|
2016-06-06 02:25:16 +02:00
|
|
|
}
|
2016-06-21 01:30:38 +02:00
|
|
|
|
|
|
|
public static function finish()
|
|
|
|
{
|
|
|
|
if (count(self::$errors)) {
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
2016-06-06 02:25:16 +02:00
|
|
|
}
|