1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-14 02:07:37 +01:00
psalm/src/CodeInspector/IssueBuffer.php

61 lines
1.3 KiB
PHP
Raw Normal View History

<?php
namespace CodeInspector;
2016-06-26 21:18:40 +02:00
class IssueBuffer
{
protected static $errors = [];
2016-06-10 00:08:25 +02:00
public static function accepts(Issue\CodeIssue $e)
{
2016-06-10 00:08:25 +02:00
$config = Config::getInstance();
if ($config->excludeIssueInFile(get_class($e), $e->getFileName())) {
return false;
}
self::add($e);
return true;
}
public static function add(Issue\CodeIssue $e)
{
$config = Config::getInstance();
2016-06-17 23:34:52 +02:00
$error_class_name = array_pop(explode('\\', get_class($e)));
$error_message = $error_class_name . ' - ' . $e->getMessage();
2016-06-27 04:03:37 +02:00
$reporting_level = $config->getReportingLevel(get_class($e));
switch ($reporting_level) {
case Config::REPORT_INFO:
echo 'INFO: ' . $error_message . PHP_EOL;
return false;
case Config::REPORT_SUPPRESS:
return false;
}
if ($config->throw_exception) {
throw new Exception\CodeException($error_message);
}
2016-06-27 04:03:37 +02:00
echo "\033[0;31m" . 'ERROR: ' . "\033[0m" . $error_message . PHP_EOL;
2016-06-17 01:02:29 +02:00
if ($config->stop_on_first_error) {
exit(1);
}
self::$errors[] = $error_message;
}
public static function finish()
{
if (count(self::$errors)) {
exit(1);
}
}
}