mirror of
https://github.com/danog/psalm.git
synced 2024-11-27 04:45:20 +01:00
Merge pull request #9846 from lptn/use-consts-for-issue-severity
Introduce and use `IssueData` constants for severity levels
This commit is contained in:
commit
5b2efad55b
@ -11,6 +11,12 @@ use const STR_PAD_LEFT;
|
||||
*/
|
||||
class IssueData
|
||||
{
|
||||
public const SEVERITY_INFO = 'info';
|
||||
public const SEVERITY_ERROR = 'error';
|
||||
|
||||
/**
|
||||
* @var self::SEVERITY_*
|
||||
*/
|
||||
public string $severity;
|
||||
|
||||
public int $line_from;
|
||||
@ -93,6 +99,7 @@ class IssueData
|
||||
public ?string $dupe_key = null;
|
||||
|
||||
/**
|
||||
* @param self::SEVERITY_* $severity
|
||||
* @param ?list<DataFlowNodeData|array{label: string, entry_path_type: string}> $taint_trace
|
||||
* @param ?list<DataFlowNodeData> $other_references
|
||||
*/
|
||||
|
@ -1552,13 +1552,13 @@ class Analyzer
|
||||
$has_info = false;
|
||||
|
||||
foreach ($issues as $issue) {
|
||||
if ($issue->severity === 'error') {
|
||||
$has_error = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if ($issue->severity === 'info') {
|
||||
$has_info = true;
|
||||
switch ($issue->severity) {
|
||||
case IssueData::SEVERITY_INFO:
|
||||
$has_info = true;
|
||||
break;
|
||||
default:
|
||||
$has_error = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -728,10 +728,9 @@ class LanguageServer extends Dispatcher
|
||||
new Position($end_line - 1, $end_column - 1),
|
||||
);
|
||||
switch ($severity) {
|
||||
case Config::REPORT_INFO:
|
||||
case IssueData::SEVERITY_INFO:
|
||||
$diagnostic_severity = DiagnosticSeverity::WARNING;
|
||||
break;
|
||||
case Config::REPORT_ERROR:
|
||||
default:
|
||||
$diagnostic_severity = DiagnosticSeverity::ERROR;
|
||||
break;
|
||||
@ -788,7 +787,7 @@ class LanguageServer extends Dispatcher
|
||||
);
|
||||
|
||||
if ($position !== false) {
|
||||
$issue_data->severity = Config::REPORT_INFO;
|
||||
$issue_data->severity = IssueData::SEVERITY_INFO;
|
||||
/** @psalm-suppress MixedArgument */
|
||||
array_splice($issue_baseline[$file][$type]['s'], $position, 1);
|
||||
/** @psalm-suppress MixedArrayAssignment, MixedOperand, MixedAssignment */
|
||||
@ -797,7 +796,7 @@ class LanguageServer extends Dispatcher
|
||||
} else {
|
||||
/** @psalm-suppress MixedArrayAssignment */
|
||||
$issue_baseline[$file][$type]['s'] = [];
|
||||
$issue_data->severity = Config::REPORT_INFO;
|
||||
$issue_data->severity = IssueData::SEVERITY_INFO;
|
||||
/** @psalm-suppress MixedArrayAssignment, MixedOperand, MixedAssignment */
|
||||
$issue_baseline[$file][$type]['o']--;
|
||||
}
|
||||
@ -806,7 +805,7 @@ class LanguageServer extends Dispatcher
|
||||
}, $data[$file_path] ?? []),
|
||||
function (IssueData $issue_data) {
|
||||
//Hide Warnings
|
||||
if ($issue_data->severity === Config::REPORT_INFO &&
|
||||
if ($issue_data->severity === IssueData::SEVERITY_INFO &&
|
||||
$this->client->clientConfiguration->hideWarnings
|
||||
) {
|
||||
return false;
|
||||
|
@ -68,6 +68,9 @@ abstract class CodeIssue
|
||||
return array_pop($fqcn_parts);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param IssueData::SEVERITY_* $severity
|
||||
*/
|
||||
public function toIssueData(string $severity): IssueData
|
||||
{
|
||||
$location = $this->code_location;
|
||||
|
@ -302,7 +302,7 @@ final class IssueBuffer
|
||||
|
||||
if ($reporting_level === Config::REPORT_INFO) {
|
||||
if ($is_tainted || !self::alreadyEmitted($emitted_key)) {
|
||||
self::$issues_data[$e->getFilePath()][] = $e->toIssueData(Config::REPORT_INFO);
|
||||
self::$issues_data[$e->getFilePath()][] = $e->toIssueData(IssueData::SEVERITY_INFO);
|
||||
|
||||
if ($is_fixable) {
|
||||
self::addFixableIssue($issue_type);
|
||||
@ -331,7 +331,7 @@ final class IssueBuffer
|
||||
|
||||
if ($is_tainted || !self::alreadyEmitted($emitted_key)) {
|
||||
++self::$error_count;
|
||||
self::$issues_data[$e->getFilePath()][] = $e->toIssueData(Config::REPORT_ERROR);
|
||||
self::$issues_data[$e->getFilePath()][] = $e->toIssueData(IssueData::SEVERITY_ERROR);
|
||||
|
||||
if ($is_fixable) {
|
||||
self::addFixableIssue($issue_type);
|
||||
@ -598,13 +598,13 @@ final class IssueBuffer
|
||||
);
|
||||
|
||||
if ($position !== false) {
|
||||
$issue_data->severity = Config::REPORT_INFO;
|
||||
$issue_data->severity = IssueData::SEVERITY_INFO;
|
||||
array_splice($issue_baseline[$file][$type]['s'], $position, 1);
|
||||
$issue_baseline[$file][$type]['o']--;
|
||||
}
|
||||
} else {
|
||||
$issue_baseline[$file][$type]['s'] = [];
|
||||
$issue_data->severity = Config::REPORT_INFO;
|
||||
$issue_data->severity = IssueData::SEVERITY_INFO;
|
||||
$issue_baseline[$file][$type]['o']--;
|
||||
}
|
||||
}
|
||||
@ -618,7 +618,7 @@ final class IssueBuffer
|
||||
foreach ($issues as $issue_name => $issue) {
|
||||
if ($issue['o'] !== 0) {
|
||||
$issues_data[$file_path][] = new IssueData(
|
||||
Config::REPORT_ERROR,
|
||||
IssueData::SEVERITY_ERROR,
|
||||
0,
|
||||
0,
|
||||
UnusedBaselineEntry::getIssueType(),
|
||||
|
@ -123,7 +123,7 @@ final class Shepherd implements AfterAnalysisInterface
|
||||
$issues = $event->getIssues();
|
||||
$normalized_data = $issues === [] ? [] : array_filter(
|
||||
array_merge(...array_values($issues)),
|
||||
static fn(IssueData $i): bool => $i->severity === 'error',
|
||||
static fn(IssueData $i): bool => $i->severity === IssueData::SEVERITY_ERROR,
|
||||
);
|
||||
|
||||
$codebase = $event->getCodebase();
|
||||
|
@ -74,7 +74,7 @@ abstract class Report
|
||||
if (!$report_options->show_info) {
|
||||
$this->issues_data = array_filter(
|
||||
$issues_data,
|
||||
static fn(IssueData $issue_data): bool => $issue_data->severity !== Config::REPORT_INFO,
|
||||
static fn(IssueData $issue_data): bool => $issue_data->severity !== IssueData::SEVERITY_INFO,
|
||||
);
|
||||
} else {
|
||||
$this->issues_data = $issues_data;
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace Psalm\Report;
|
||||
|
||||
use Psalm\Config;
|
||||
use Psalm\Internal\Analyzer\IssueData;
|
||||
use Psalm\Report;
|
||||
use Symfony\Component\Console\Helper\Table;
|
||||
use Symfony\Component\Console\Output\BufferedOutput;
|
||||
@ -31,7 +32,7 @@ final class CompactReport extends Report
|
||||
|
||||
$output = [];
|
||||
foreach ($this->issues_data as $i => $issue_data) {
|
||||
if (!$this->show_info && $issue_data->severity === Config::REPORT_INFO) {
|
||||
if (!$this->show_info && $issue_data->severity === IssueData::SEVERITY_INFO) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
namespace Psalm\Report;
|
||||
|
||||
use Psalm\Config;
|
||||
use Psalm\Internal\Analyzer\IssueData;
|
||||
use Psalm\Report;
|
||||
|
||||
use function sprintf;
|
||||
@ -18,7 +18,7 @@ final class EmacsReport extends Report
|
||||
$issue_data->file_path,
|
||||
$issue_data->line_from,
|
||||
$issue_data->column_from,
|
||||
($issue_data->severity === Config::REPORT_ERROR ? 'error' : 'warning'),
|
||||
($issue_data->severity === IssueData::SEVERITY_ERROR ? 'error' : 'warning'),
|
||||
$issue_data->type,
|
||||
$issue_data->message,
|
||||
$issue_data->link,
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
namespace Psalm\Report;
|
||||
|
||||
use Psalm\Config;
|
||||
use Psalm\Internal\Analyzer\IssueData;
|
||||
use Psalm\Report;
|
||||
|
||||
use function sprintf;
|
||||
@ -34,7 +34,7 @@ final class GithubActionsReport extends Report
|
||||
|
||||
$output .= sprintf(
|
||||
'::%1$s %2$s::%3$s',
|
||||
($issue_data->severity === Config::REPORT_ERROR ? 'error' : 'warning'),
|
||||
($issue_data->severity === IssueData::SEVERITY_ERROR ? 'error' : 'warning'),
|
||||
$properties,
|
||||
$data,
|
||||
) . "\n";
|
||||
|
@ -27,8 +27,8 @@ final class JunitReport extends Report
|
||||
$ndata = [];
|
||||
|
||||
foreach ($this->issues_data as $error) {
|
||||
$is_error = $error->severity === Config::REPORT_ERROR;
|
||||
$is_warning = $error->severity === Config::REPORT_INFO;
|
||||
$is_error = $error->severity === IssueData::SEVERITY_ERROR;
|
||||
$is_warning = $error->severity === IssueData::SEVERITY_INFO;
|
||||
|
||||
if (!$is_error && !$is_warning) {
|
||||
continue;
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
namespace Psalm\Report;
|
||||
|
||||
use Psalm\Config;
|
||||
use Psalm\Internal\Analyzer\IssueData;
|
||||
use Psalm\Report;
|
||||
|
||||
use function sprintf;
|
||||
@ -18,7 +18,7 @@ final class TextReport extends Report
|
||||
$issue_data->file_path,
|
||||
$issue_data->line_from,
|
||||
$issue_data->column_from,
|
||||
($issue_data->severity === Config::REPORT_ERROR ? 'error' : 'warning'),
|
||||
($issue_data->severity === IssueData::SEVERITY_ERROR ? 'error' : 'warning'),
|
||||
$issue_data->type,
|
||||
$issue_data->message,
|
||||
) . "\n";
|
||||
|
@ -75,7 +75,7 @@ class ByIssueLevelAndTypeReportTest extends TestCase
|
||||
private function issueData(int $errorLevel, string $type): IssueData
|
||||
{
|
||||
return new IssueData(
|
||||
'error',
|
||||
IssueData::SEVERITY_ERROR,
|
||||
1,
|
||||
1,
|
||||
$type,
|
||||
|
@ -187,7 +187,7 @@ bar
|
||||
[
|
||||
'sample/sample-file.php' => [
|
||||
new IssueData(
|
||||
'error',
|
||||
IssueData::SEVERITY_ERROR,
|
||||
0,
|
||||
0,
|
||||
'MixedAssignment',
|
||||
@ -204,7 +204,7 @@ bar
|
||||
0,
|
||||
),
|
||||
new IssueData(
|
||||
'error',
|
||||
IssueData::SEVERITY_ERROR,
|
||||
0,
|
||||
0,
|
||||
'MixedAssignment',
|
||||
@ -221,7 +221,7 @@ bar
|
||||
0,
|
||||
),
|
||||
new IssueData(
|
||||
'error',
|
||||
IssueData::SEVERITY_ERROR,
|
||||
0,
|
||||
0,
|
||||
'MixedAssignment',
|
||||
@ -238,7 +238,7 @@ bar
|
||||
0,
|
||||
),
|
||||
new IssueData(
|
||||
'error',
|
||||
IssueData::SEVERITY_ERROR,
|
||||
0,
|
||||
0,
|
||||
'MixedOperand',
|
||||
@ -274,7 +274,7 @@ bar
|
||||
],
|
||||
'sample/sample-file2.php' => [
|
||||
new IssueData(
|
||||
'error',
|
||||
IssueData::SEVERITY_ERROR,
|
||||
0,
|
||||
0,
|
||||
'MixedAssignment',
|
||||
@ -291,7 +291,7 @@ bar
|
||||
0,
|
||||
),
|
||||
new IssueData(
|
||||
'error',
|
||||
IssueData::SEVERITY_ERROR,
|
||||
0,
|
||||
0,
|
||||
'MixedAssignment',
|
||||
@ -308,7 +308,7 @@ bar
|
||||
0,
|
||||
),
|
||||
new IssueData(
|
||||
'error',
|
||||
IssueData::SEVERITY_ERROR,
|
||||
0,
|
||||
0,
|
||||
'TypeCoercion',
|
||||
@ -410,7 +410,7 @@ bar
|
||||
$newIssues = [
|
||||
'sample/sample-file.php' => [
|
||||
new IssueData(
|
||||
'error',
|
||||
IssueData::SEVERITY_ERROR,
|
||||
0,
|
||||
0,
|
||||
'MixedAssignment',
|
||||
@ -427,7 +427,7 @@ bar
|
||||
0,
|
||||
),
|
||||
new IssueData(
|
||||
'error',
|
||||
IssueData::SEVERITY_ERROR,
|
||||
0,
|
||||
0,
|
||||
'MixedAssignment',
|
||||
@ -444,7 +444,7 @@ bar
|
||||
0,
|
||||
),
|
||||
new IssueData(
|
||||
'error',
|
||||
IssueData::SEVERITY_ERROR,
|
||||
0,
|
||||
0,
|
||||
'MixedOperand',
|
||||
@ -461,7 +461,7 @@ bar
|
||||
0,
|
||||
),
|
||||
new IssueData(
|
||||
'error',
|
||||
IssueData::SEVERITY_ERROR,
|
||||
0,
|
||||
0,
|
||||
'MixedOperand',
|
||||
@ -480,7 +480,7 @@ bar
|
||||
],
|
||||
'sample/sample-file2.php' => [
|
||||
new IssueData(
|
||||
'error',
|
||||
IssueData::SEVERITY_ERROR,
|
||||
0,
|
||||
0,
|
||||
'TypeCoercion',
|
||||
|
@ -24,7 +24,7 @@ class IssueBufferTest extends TestCase
|
||||
IssueBuffer::addIssues([
|
||||
'/path/one.php' => [
|
||||
new IssueData(
|
||||
"error",
|
||||
IssueData::SEVERITY_ERROR,
|
||||
0,
|
||||
0,
|
||||
"MissingPropertyType",
|
||||
@ -43,7 +43,7 @@ class IssueBufferTest extends TestCase
|
||||
],
|
||||
'/path/two.php' => [
|
||||
new IssueData(
|
||||
"error",
|
||||
IssueData::SEVERITY_ERROR,
|
||||
0,
|
||||
0,
|
||||
"MissingPropertyType",
|
||||
@ -62,7 +62,7 @@ class IssueBufferTest extends TestCase
|
||||
],
|
||||
'/path/three.php' => [
|
||||
new IssueData(
|
||||
"error",
|
||||
IssueData::SEVERITY_ERROR,
|
||||
0,
|
||||
0,
|
||||
"MissingPropertyType",
|
||||
@ -81,7 +81,7 @@ class IssueBufferTest extends TestCase
|
||||
],
|
||||
'/path/four.php' => [
|
||||
new IssueData(
|
||||
"error",
|
||||
IssueData::SEVERITY_ERROR,
|
||||
0,
|
||||
0,
|
||||
"MissingPropertyType",
|
||||
|
@ -833,7 +833,7 @@ class ReportOutputTest extends TestCase
|
||||
{
|
||||
$issues_data = [
|
||||
22 => new IssueData(
|
||||
'info',
|
||||
IssueData::SEVERITY_INFO,
|
||||
15,
|
||||
15,
|
||||
'PossiblyUndefinedGlobalVariable',
|
||||
|
Loading…
Reference in New Issue
Block a user