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
|
|
|
|
2018-11-06 03:57:36 +01:00
|
|
|
use Psalm\Internal\Analyzer\ProjectAnalyzer;
|
2018-03-21 03:36:03 +01:00
|
|
|
use Psalm\Issue\ClassIssue;
|
2017-03-13 23:06:56 +01:00
|
|
|
use Psalm\Issue\CodeIssue;
|
2019-01-02 17:18:22 +01:00
|
|
|
use Psalm\Issue\DuplicateClass;
|
|
|
|
use Psalm\Issue\DuplicateMethod;
|
2018-03-21 03:36:03 +01:00
|
|
|
use Psalm\Issue\MethodIssue;
|
2018-05-11 06:07:41 +02:00
|
|
|
use Psalm\Issue\PropertyIssue;
|
2018-12-09 21:47:20 +01:00
|
|
|
use Psalm\Output\Compact;
|
|
|
|
use Psalm\Output\Console;
|
|
|
|
use Psalm\Output\Emacs;
|
|
|
|
use Psalm\Output\Json;
|
|
|
|
use Psalm\Output\Pylint;
|
2018-12-18 19:13:21 +01:00
|
|
|
use Psalm\Output\Text;
|
2018-12-09 21:47:20 +01:00
|
|
|
use Psalm\Output\Xml;
|
2016-08-13 20:20:46 +02:00
|
|
|
|
2016-06-26 21:18:40 +02:00
|
|
|
class IssueBuffer
|
2016-06-06 02:25:16 +02:00
|
|
|
{
|
2017-07-25 22:11:02 +02:00
|
|
|
/**
|
2018-02-20 00:16:09 +01:00
|
|
|
* @var array<int, array{severity: string, line_from: int, line_to: int, type: string, message: string,
|
|
|
|
* file_name: string, file_path: string, snippet: string, from: int, to: int,
|
2018-11-09 06:46:13 +01:00
|
|
|
* snippet_from: int, snippet_to: int, column_from: int, column_to: int, selected_text: string}>
|
2017-07-25 22:11:02 +02:00
|
|
|
*/
|
|
|
|
protected static $issues_data = [];
|
|
|
|
|
2016-12-08 04:38:57 +01:00
|
|
|
/**
|
|
|
|
* @var array<int, array>
|
|
|
|
*/
|
2017-07-25 22:11:02 +02:00
|
|
|
protected static $console_issues = [];
|
2016-12-08 04:38:57 +01:00
|
|
|
|
2016-11-02 07:29:00 +01:00
|
|
|
/**
|
2017-01-14 07:24:27 +01:00
|
|
|
* @var int
|
2016-11-02 07:29:00 +01:00
|
|
|
*/
|
2017-01-14 07:24:27 +01:00
|
|
|
protected static $error_count = 0;
|
2016-11-01 05:39:41 +01:00
|
|
|
|
2016-11-02 07:29:00 +01:00
|
|
|
/**
|
|
|
|
* @var array<string, bool>
|
|
|
|
*/
|
2016-10-19 00:55:53 +02:00
|
|
|
protected static $emitted = [];
|
2016-06-21 01:30:38 +02:00
|
|
|
|
2017-03-13 23:06:56 +01:00
|
|
|
/** @var int */
|
|
|
|
protected static $recording_level = 0;
|
|
|
|
|
|
|
|
/** @var array<int, array<int, CodeIssue>> */
|
|
|
|
protected static $recorded_issues = [];
|
|
|
|
|
2016-11-02 07:29:00 +01:00
|
|
|
/**
|
2017-03-13 23:06:56 +01:00
|
|
|
* @param CodeIssue $e
|
|
|
|
* @param array $suppressed_issues
|
2017-05-27 02:16:18 +02:00
|
|
|
*
|
2016-11-02 07:29:00 +01:00
|
|
|
* @return bool
|
|
|
|
*/
|
2017-03-13 23:06:56 +01:00
|
|
|
public static function accepts(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
|
|
|
|
2017-05-27 02:05:57 +02:00
|
|
|
if (in_array($issue_type, $suppressed_issues, true)) {
|
2016-07-22 19:29:46 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-01-02 18:10:52 +01:00
|
|
|
if (!$config->reportIssueInFile($issue_type, $e->getFilePath())) {
|
2016-06-10 00:08:25 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-03-21 03:36:03 +01:00
|
|
|
if ($e instanceof ClassIssue
|
|
|
|
&& $config->getReportingLevelForClass($issue_type, $e->fq_classlike_name) === Config::REPORT_SUPPRESS
|
|
|
|
) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($e instanceof MethodIssue
|
|
|
|
&& $config->getReportingLevelForMethod($issue_type, $e->method_id) === Config::REPORT_SUPPRESS
|
|
|
|
) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-05-11 06:07:41 +02:00
|
|
|
if ($e instanceof PropertyIssue
|
|
|
|
&& $config->getReportingLevelForProperty($issue_type, $e->property_id) === Config::REPORT_SUPPRESS
|
|
|
|
) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-03-18 22:26:28 +01:00
|
|
|
$parent_issue_type = self::getParentIssueType($issue_type);
|
2018-03-18 21:39:34 +01:00
|
|
|
|
2018-03-18 22:26:28 +01:00
|
|
|
if ($parent_issue_type) {
|
|
|
|
if (in_array($parent_issue_type, $suppressed_issues, true)) {
|
2018-03-18 21:39:34 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-03-18 22:26:28 +01:00
|
|
|
if (!$config->reportIssueInFile($parent_issue_type, $e->getFilePath())) {
|
2018-03-18 21:39:34 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-13 23:06:56 +01:00
|
|
|
if (self::$recording_level > 0) {
|
|
|
|
self::$recorded_issues[self::$recording_level][] = $e;
|
2017-05-25 04:07:49 +02:00
|
|
|
|
2017-03-13 23:06:56 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-08-08 20:36:18 +02:00
|
|
|
return self::add($e);
|
2016-06-27 19:22:16 +02:00
|
|
|
}
|
|
|
|
|
2018-03-18 22:26:28 +01:00
|
|
|
/**
|
|
|
|
* @param string $issue_type
|
|
|
|
* @return string|null
|
|
|
|
*/
|
|
|
|
private static function getParentIssueType($issue_type)
|
|
|
|
{
|
|
|
|
if (strpos($issue_type, 'Possibly') === 0) {
|
|
|
|
$stripped_issue_type = preg_replace('/^Possibly(False|Null)?/', '', $issue_type);
|
|
|
|
|
|
|
|
if (strpos($stripped_issue_type, 'Invalid') === false && strpos($stripped_issue_type, 'Un') !== 0) {
|
|
|
|
$stripped_issue_type = 'Invalid' . $stripped_issue_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $stripped_issue_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (preg_match('/^(False|Null)[A-Z]/', $issue_type)) {
|
|
|
|
return preg_replace('/^(False|Null)/', 'Invalid', $issue_type);
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2016-11-02 07:29:00 +01:00
|
|
|
/**
|
2017-03-13 23:06:56 +01:00
|
|
|
* @param CodeIssue $e
|
2017-05-27 02:16:18 +02:00
|
|
|
*
|
2016-11-02 07:29:00 +01:00
|
|
|
* @throws Exception\CodeException
|
2017-05-27 02:16:18 +02:00
|
|
|
*
|
|
|
|
* @return bool
|
2016-11-02 07:29:00 +01:00
|
|
|
*/
|
2017-03-13 23:06:56 +01:00
|
|
|
public static function add(CodeIssue $e)
|
2016-06-27 19:22:16 +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-06-17 23:34:52 +02:00
|
|
|
|
2018-11-11 18:01:14 +01:00
|
|
|
$project_analyzer = ProjectAnalyzer::getInstance();
|
2018-01-06 01:49:27 +01:00
|
|
|
|
2018-11-11 18:01:14 +01:00
|
|
|
if (!$project_analyzer->show_issues) {
|
2018-01-06 01:49:27 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-12-08 04:38:57 +01:00
|
|
|
$error_message = $issue_type . ' - ' . $e->getShortLocation() . ' - ' . $e->getMessage();
|
2016-07-22 19:29:46 +02:00
|
|
|
|
2017-02-12 19:38:41 +01:00
|
|
|
$reporting_level = $config->getReportingLevelForFile($issue_type, $e->getFilePath());
|
2016-06-27 04:03:37 +02:00
|
|
|
|
2018-03-18 22:26:28 +01:00
|
|
|
$parent_issue_type = self::getParentIssueType($issue_type);
|
|
|
|
|
|
|
|
if ($parent_issue_type && $reporting_level === Config::REPORT_ERROR) {
|
|
|
|
$parent_reporting_level = $config->getReportingLevelForFile($parent_issue_type, $e->getFilePath());
|
|
|
|
|
|
|
|
if ($parent_reporting_level !== $reporting_level) {
|
|
|
|
$reporting_level = $parent_reporting_level;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-04 01:11:30 +01:00
|
|
|
if ($reporting_level === Config::REPORT_SUPPRESS) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($reporting_level === Config::REPORT_INFO) {
|
2018-09-27 00:08:23 +02:00
|
|
|
if (!self::alreadyEmitted($error_message)) {
|
2017-07-25 22:11:02 +02:00
|
|
|
self::$issues_data[] = $e->toArray(Config::REPORT_INFO);
|
2016-12-04 01:11:30 +01:00
|
|
|
}
|
2017-05-25 04:07:49 +02:00
|
|
|
|
2016-12-04 01:11:30 +01:00
|
|
|
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-10-19 00:55:53 +02:00
|
|
|
if (!self::alreadyEmitted($error_message)) {
|
2018-09-26 00:37:24 +02:00
|
|
|
++self::$error_count;
|
2017-07-25 22:11:02 +02:00
|
|
|
self::$issues_data[] = $e->toArray(Config::REPORT_ERROR);
|
2016-10-19 00:55:53 +02:00
|
|
|
}
|
2016-06-17 01:02:29 +02:00
|
|
|
|
2016-08-08 20:36:18 +02:00
|
|
|
return true;
|
2016-06-06 02:25:16 +02:00
|
|
|
}
|
2016-06-21 01:30:38 +02:00
|
|
|
|
2016-12-08 04:38:57 +01:00
|
|
|
/**
|
2018-09-26 00:37:24 +02:00
|
|
|
* @return array<int, array{severity: string, line_from: int, line_to: int, type: string, message: string,
|
|
|
|
* file_name: string, file_path: string, snippet: string, from: int, to: int, snippet_from: int, snippet_to: int,
|
2018-11-09 06:46:13 +01:00
|
|
|
* column_from: int, column_to: int, selected_text: string}>
|
2016-12-08 04:38:57 +01:00
|
|
|
*/
|
2017-07-25 22:11:02 +02:00
|
|
|
public static function getIssuesData()
|
2016-12-08 04:38:57 +01:00
|
|
|
{
|
2017-07-25 22:11:02 +02:00
|
|
|
return self::$issues_data;
|
2016-12-08 04:38:57 +01:00
|
|
|
}
|
|
|
|
|
2018-09-26 00:37:24 +02:00
|
|
|
/**
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public static function getErrorCount()
|
|
|
|
{
|
|
|
|
return self::$error_count;
|
|
|
|
}
|
|
|
|
|
2016-12-08 04:38:57 +01:00
|
|
|
/**
|
2018-03-17 23:05:50 +01:00
|
|
|
* @param array<int, array{severity: string, line_from: int, line_to: int, type: string, message: string,
|
2017-07-25 22:11:02 +02:00
|
|
|
* file_name: string, file_path: string, snippet: string, from: int, to: int, snippet_from: int,
|
2018-02-20 00:16:09 +01:00
|
|
|
* snippet_to: int, column_from: int, column_to: int}> $issues_data
|
2017-05-27 02:16:18 +02:00
|
|
|
*
|
2017-07-25 22:11:02 +02:00
|
|
|
* @return void
|
2016-12-08 04:38:57 +01:00
|
|
|
*/
|
2017-07-25 22:11:02 +02:00
|
|
|
public static function addIssues(array $issues_data)
|
2016-12-08 04:38:57 +01:00
|
|
|
{
|
2018-11-01 18:22:38 +01:00
|
|
|
foreach ($issues_data as $issue) {
|
2018-11-01 22:03:08 +01:00
|
|
|
$error_message = $issue['type']
|
|
|
|
. ' - ' . $issue['file_name']
|
|
|
|
. ':' . $issue['line_from']
|
|
|
|
. ' - ' . $issue['message'];
|
2018-11-01 18:22:38 +01:00
|
|
|
|
|
|
|
if (!self::alreadyEmitted($error_message)) {
|
|
|
|
self::$issues_data[] = $issue;
|
|
|
|
}
|
|
|
|
}
|
2016-12-08 04:38:57 +01:00
|
|
|
}
|
|
|
|
|
2016-11-02 07:29:00 +01:00
|
|
|
/**
|
2018-11-11 18:01:14 +01:00
|
|
|
* @param ProjectAnalyzer $project_analyzer
|
2018-10-30 15:32:20 +01:00
|
|
|
* @param bool $is_full
|
|
|
|
* @param float $start_time
|
|
|
|
* @param bool $add_stats
|
2018-11-09 06:46:13 +01:00
|
|
|
* @param array<string,array<string,array{o:int, s:array<int, string>}>> $issue_baseline
|
2017-05-27 02:16:18 +02:00
|
|
|
*
|
2016-11-02 07:29:00 +01:00
|
|
|
* @return void
|
|
|
|
*/
|
2018-01-31 23:09:09 +01:00
|
|
|
public static function finish(
|
2018-11-11 18:01:14 +01:00
|
|
|
ProjectAnalyzer $project_analyzer,
|
2018-10-30 15:32:20 +01:00
|
|
|
bool $is_full,
|
|
|
|
float $start_time,
|
|
|
|
bool $add_stats = false,
|
|
|
|
array $issue_baseline = []
|
2018-01-31 23:09:09 +01:00
|
|
|
) {
|
2018-11-11 18:01:14 +01:00
|
|
|
if ($project_analyzer->output_format === ProjectAnalyzer::TYPE_CONSOLE) {
|
2018-04-16 20:05:37 +02:00
|
|
|
echo "\n";
|
|
|
|
}
|
2018-03-18 23:27:10 +01:00
|
|
|
|
2018-11-11 18:19:53 +01:00
|
|
|
$codebase = $project_analyzer->getCodebase();
|
|
|
|
|
2018-03-18 23:04:50 +01:00
|
|
|
$error_count = 0;
|
2018-03-18 23:27:10 +01:00
|
|
|
$info_count = 0;
|
2017-07-25 22:11:02 +02:00
|
|
|
|
|
|
|
if (self::$issues_data) {
|
2017-12-10 17:22:36 +01:00
|
|
|
usort(
|
|
|
|
self::$issues_data,
|
|
|
|
/** @return int */
|
|
|
|
function (array $d1, array $d2) {
|
|
|
|
if ($d1['file_path'] === $d2['file_path']) {
|
2018-02-20 00:16:09 +01:00
|
|
|
if ($d1['line_from'] === $d2['line_from']) {
|
|
|
|
if ($d1['column_from'] === $d2['column_from']) {
|
2017-12-10 17:22:36 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-02-20 00:16:09 +01:00
|
|
|
return $d1['column_from'] > $d2['column_from'] ? 1 : -1;
|
2017-12-10 17:22:36 +01:00
|
|
|
}
|
|
|
|
|
2018-02-20 00:16:09 +01:00
|
|
|
return $d1['line_from'] > $d2['line_from'] ? 1 : -1;
|
2017-12-10 17:22:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return $d1['file_path'] > $d2['file_path'] ? 1 : -1;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2018-10-30 15:32:20 +01:00
|
|
|
if (!empty($issue_baseline)) {
|
|
|
|
// Set severity for issues in baseline to INFO
|
|
|
|
foreach (self::$issues_data as $key => $issue_data) {
|
|
|
|
$file = $issue_data['file_name'];
|
|
|
|
$type = $issue_data['type'];
|
|
|
|
|
2018-11-09 06:46:13 +01:00
|
|
|
if (isset($issue_baseline[$file][$type]) && $issue_baseline[$file][$type]['o'] > 0) {
|
|
|
|
if ($issue_baseline[$file][$type]['o'] === count($issue_baseline[$file][$type]['s'])) {
|
|
|
|
$position = array_search($issue_data['selected_text'], $issue_baseline[$file][$type]['s']);
|
|
|
|
|
|
|
|
if ($position !== false) {
|
|
|
|
$issue_data['severity'] = Config::REPORT_INFO;
|
|
|
|
array_splice($issue_baseline[$file][$type]['s'], $position, 1);
|
|
|
|
$issue_baseline[$file][$type]['o'] = $issue_baseline[$file][$type]['o'] - 1;
|
|
|
|
}
|
|
|
|
} else {
|
2018-11-09 17:38:40 +01:00
|
|
|
$issue_baseline[$file][$type]['s'] = [];
|
2018-11-09 06:46:13 +01:00
|
|
|
$issue_data['severity'] = Config::REPORT_INFO;
|
|
|
|
$issue_baseline[$file][$type]['o'] = $issue_baseline[$file][$type]['o'] - 1;
|
|
|
|
}
|
2018-10-30 15:32:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
self::$issues_data[$key] = $issue_data;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-08 17:18:48 +02:00
|
|
|
foreach (self::$issues_data as $issue_data) {
|
|
|
|
if ($issue_data['severity'] === Config::REPORT_ERROR) {
|
2018-03-18 23:04:50 +01:00
|
|
|
++$error_count;
|
2018-03-18 23:27:10 +01:00
|
|
|
} else {
|
|
|
|
++$info_count;
|
2017-07-25 22:11:02 +02:00
|
|
|
}
|
2017-09-08 17:18:48 +02:00
|
|
|
}
|
2017-07-25 22:11:02 +02:00
|
|
|
|
2018-06-04 16:19:20 +02:00
|
|
|
echo self::getOutput(
|
2018-11-11 18:01:14 +01:00
|
|
|
$project_analyzer->output_format,
|
|
|
|
$project_analyzer->use_color,
|
|
|
|
$project_analyzer->show_snippet,
|
|
|
|
$project_analyzer->show_info
|
2018-06-04 16:19:20 +02:00
|
|
|
);
|
2017-09-27 00:18:24 +02:00
|
|
|
}
|
2018-03-18 23:27:10 +01:00
|
|
|
|
2018-11-11 18:01:14 +01:00
|
|
|
foreach ($project_analyzer->reports as $format => $path) {
|
2017-09-27 00:18:24 +02:00
|
|
|
file_put_contents(
|
|
|
|
$path,
|
2018-11-11 18:01:14 +01:00
|
|
|
self::getOutput($format, $project_analyzer->use_color)
|
2017-09-27 00:18:24 +02:00
|
|
|
);
|
2017-07-25 22:11:02 +02:00
|
|
|
}
|
|
|
|
|
2018-11-11 18:01:14 +01:00
|
|
|
if ($project_analyzer->output_format === ProjectAnalyzer::TYPE_CONSOLE) {
|
2018-04-16 20:05:37 +02:00
|
|
|
echo str_repeat('-', 30) . "\n";
|
2018-03-18 23:04:50 +01:00
|
|
|
|
2018-04-16 20:05:37 +02:00
|
|
|
if ($error_count) {
|
2018-11-11 18:01:14 +01:00
|
|
|
echo ($project_analyzer->use_color
|
2018-04-16 20:05:37 +02:00
|
|
|
? "\e[0;31m" . $error_count . " errors\e[0m"
|
|
|
|
: $error_count . ' errors'
|
|
|
|
) . ' found' . "\n";
|
|
|
|
} else {
|
|
|
|
echo 'No errors found!' . "\n";
|
|
|
|
}
|
2018-03-18 23:27:10 +01:00
|
|
|
|
2018-11-11 18:01:14 +01:00
|
|
|
if ($info_count && $project_analyzer->show_info) {
|
2018-04-16 20:05:37 +02:00
|
|
|
echo str_repeat('-', 30) . "\n";
|
2018-03-18 23:27:10 +01:00
|
|
|
|
2018-04-16 20:05:37 +02:00
|
|
|
echo $info_count . ' other issues found.' . "\n"
|
|
|
|
. 'You can hide them with ' .
|
2018-11-11 18:01:14 +01:00
|
|
|
($project_analyzer->use_color
|
2018-04-16 20:05:37 +02:00
|
|
|
? "\e[30;48;5;195m--show-info=false\e[0m"
|
|
|
|
: '--show-info=false') . "\n";
|
|
|
|
}
|
2018-03-18 23:27:10 +01:00
|
|
|
|
2018-04-16 20:05:37 +02:00
|
|
|
echo str_repeat('-', 30) . "\n" . "\n";
|
2018-03-18 23:04:50 +01:00
|
|
|
|
2018-04-16 20:05:37 +02:00
|
|
|
if ($start_time) {
|
2018-10-10 22:05:06 +02:00
|
|
|
echo 'Checks took ' . number_format(microtime(true) - $start_time, 2) . ' seconds';
|
2018-04-16 20:05:37 +02:00
|
|
|
echo ' and used ' . number_format(memory_get_peak_usage() / (1024 * 1024), 3) . 'MB of memory' . "\n";
|
2018-01-31 22:08:52 +01:00
|
|
|
|
2018-04-16 20:05:37 +02:00
|
|
|
if ($is_full) {
|
2018-11-06 03:57:36 +01:00
|
|
|
$analysis_summary = $codebase->analyzer->getTypeInferenceSummary();
|
2018-06-04 00:31:43 +02:00
|
|
|
echo $analysis_summary . "\n";
|
2018-04-16 20:05:37 +02:00
|
|
|
}
|
2018-01-31 23:09:09 +01:00
|
|
|
|
2018-04-16 20:05:37 +02:00
|
|
|
if ($add_stats) {
|
|
|
|
echo '-----------------' . "\n";
|
2018-11-06 03:57:36 +01:00
|
|
|
echo $codebase->analyzer->getNonMixedStats();
|
2018-04-16 20:05:37 +02:00
|
|
|
echo "\n";
|
|
|
|
}
|
2018-01-31 22:08:52 +01:00
|
|
|
}
|
2016-12-15 01:24:16 +01:00
|
|
|
}
|
|
|
|
|
2018-03-18 23:04:50 +01:00
|
|
|
if ($error_count) {
|
2016-06-21 01:30:38 +02:00
|
|
|
exit(1);
|
|
|
|
}
|
2016-10-07 06:58:08 +02:00
|
|
|
|
2016-11-06 05:59:29 +01:00
|
|
|
if ($is_full && $start_time) {
|
2018-11-11 18:19:53 +01:00
|
|
|
$codebase->file_reference_provider->removeDeletedFilesFromReferences();
|
2018-09-28 22:18:45 +02:00
|
|
|
|
2018-11-11 18:19:53 +01:00
|
|
|
if ($codebase->statements_provider->parser_cache_provider) {
|
|
|
|
$codebase->statements_provider->parser_cache_provider->processSuccessfulRun($start_time);
|
2018-09-28 22:18:45 +02:00
|
|
|
}
|
2016-10-07 06:58:08 +02:00
|
|
|
}
|
2016-06-21 01:30:38 +02:00
|
|
|
}
|
2016-10-19 00:55:53 +02:00
|
|
|
|
2016-10-30 17:46:18 +01:00
|
|
|
/**
|
2017-09-08 17:18:48 +02:00
|
|
|
* @param string $format
|
2018-06-04 16:19:20 +02:00
|
|
|
* @param bool $use_color
|
|
|
|
* @param bool $show_snippet
|
2018-09-27 00:08:23 +02:00
|
|
|
* @param bool $show_info
|
2017-09-08 17:18:48 +02:00
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2018-09-27 00:08:23 +02:00
|
|
|
public static function getOutput($format, $use_color, $show_snippet = true, $show_info = true)
|
2017-09-08 17:18:48 +02:00
|
|
|
{
|
2018-12-09 21:47:20 +01:00
|
|
|
switch ($format) {
|
|
|
|
case ProjectAnalyzer::TYPE_COMPACT:
|
|
|
|
$output = new Compact(self::$issues_data, $use_color, $show_snippet, $show_info);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ProjectAnalyzer::TYPE_EMACS:
|
|
|
|
$output = new Emacs(self::$issues_data, $use_color, $show_snippet, $show_info);
|
|
|
|
break;
|
|
|
|
|
2018-12-18 19:13:21 +01:00
|
|
|
case ProjectAnalyzer::TYPE_TEXT:
|
|
|
|
$output = new Text(self::$issues_data, $use_color, $show_snippet, $show_info);
|
|
|
|
break;
|
|
|
|
|
2018-12-09 21:47:20 +01:00
|
|
|
case ProjectAnalyzer::TYPE_JSON:
|
|
|
|
$output = new Json(self::$issues_data, $use_color, $show_snippet, $show_info);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ProjectAnalyzer::TYPE_PYLINT:
|
|
|
|
$output = new Pylint(self::$issues_data, $use_color, $show_snippet, $show_info);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ProjectAnalyzer::TYPE_XML:
|
|
|
|
$output = new Xml(self::$issues_data, $use_color, $show_snippet, $show_info);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ProjectAnalyzer::TYPE_CONSOLE:
|
|
|
|
default:
|
|
|
|
$output = new Console(self::$issues_data, $use_color, $show_snippet, $show_info);
|
|
|
|
break;
|
2017-09-08 17:18:48 +02:00
|
|
|
}
|
|
|
|
|
2018-12-09 21:47:20 +01:00
|
|
|
return $output->create();
|
2017-09-08 17:18:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-10-30 17:46:18 +01:00
|
|
|
* @param string $message
|
2017-05-27 02:16:18 +02:00
|
|
|
*
|
2016-10-30 17:46:18 +01:00
|
|
|
* @return bool
|
|
|
|
*/
|
2016-10-19 00:55:53 +02:00
|
|
|
protected static function alreadyEmitted($message)
|
|
|
|
{
|
|
|
|
$sham = sha1($message);
|
|
|
|
|
|
|
|
if (isset(self::$emitted[$sham])) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
self::$emitted[$sham] = true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2016-12-08 21:57:18 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public static function clearCache()
|
|
|
|
{
|
2017-07-25 22:11:02 +02:00
|
|
|
self::$issues_data = [];
|
2016-12-08 21:57:18 +01:00
|
|
|
self::$emitted = [];
|
2017-01-14 07:24:27 +01:00
|
|
|
self::$error_count = 0;
|
2017-03-13 23:06:56 +01:00
|
|
|
self::$recording_level = 0;
|
|
|
|
self::$recorded_issues = [];
|
2017-07-25 22:11:02 +02:00
|
|
|
self::$console_issues = [];
|
2017-03-13 23:06:56 +01:00
|
|
|
}
|
|
|
|
|
2018-10-17 21:52:26 +02:00
|
|
|
/**
|
|
|
|
* @return array<int, array{severity: string, line_from: int, line_to: int, type: string, message: string,
|
|
|
|
* file_name: string, file_path: string, snippet: string, from: int, to: int, snippet_from: int, snippet_to: int,
|
|
|
|
* column_from: int, column_to: int}>
|
|
|
|
*/
|
|
|
|
public static function clear()
|
|
|
|
{
|
|
|
|
$current_data = self::$issues_data;
|
|
|
|
self::$issues_data = [];
|
|
|
|
self::$emitted = [];
|
|
|
|
return $current_data;
|
|
|
|
}
|
|
|
|
|
2017-06-29 06:28:37 +02:00
|
|
|
/**
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public static function isRecording()
|
|
|
|
{
|
|
|
|
return self::$recording_level > 0;
|
|
|
|
}
|
|
|
|
|
2017-03-13 23:06:56 +01:00
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public static function startRecording()
|
|
|
|
{
|
2017-05-27 02:05:57 +02:00
|
|
|
++self::$recording_level;
|
2017-03-13 23:06:56 +01:00
|
|
|
self::$recorded_issues[self::$recording_level] = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public static function stopRecording()
|
|
|
|
{
|
|
|
|
if (self::$recording_level === 0) {
|
|
|
|
throw new \UnexpectedValueException('Cannot stop recording - already at base level');
|
|
|
|
}
|
|
|
|
|
2017-05-27 02:05:57 +02:00
|
|
|
--self::$recording_level;
|
2017-03-13 23:06:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array<int, CodeIssue>
|
|
|
|
*/
|
|
|
|
public static function clearRecordingLevel()
|
|
|
|
{
|
|
|
|
if (self::$recording_level === 0) {
|
|
|
|
throw new \UnexpectedValueException('Not currently recording');
|
|
|
|
}
|
|
|
|
|
|
|
|
$recorded_issues = self::$recorded_issues[self::$recording_level];
|
|
|
|
|
|
|
|
self::$recorded_issues[self::$recording_level] = [];
|
|
|
|
|
|
|
|
return $recorded_issues;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public static function bubbleUp(CodeIssue $e)
|
|
|
|
{
|
|
|
|
if (self::$recording_level === 0) {
|
|
|
|
self::add($e);
|
2017-05-25 04:07:49 +02:00
|
|
|
|
2017-03-13 23:06:56 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
self::$recorded_issues[self::$recording_level][] = $e;
|
2016-12-08 21:57:18 +01:00
|
|
|
}
|
2016-06-06 02:25:16 +02:00
|
|
|
}
|