diff --git a/src/Psalm/Internal/Analyzer/IssueData.php b/src/Psalm/Internal/Analyzer/IssueData.php index 6b273c0b1..72e72b21b 100644 --- a/src/Psalm/Internal/Analyzer/IssueData.php +++ b/src/Psalm/Internal/Analyzer/IssueData.php @@ -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 $taint_trace * @param ?list $other_references */ diff --git a/src/Psalm/Internal/Codebase/Analyzer.php b/src/Psalm/Internal/Codebase/Analyzer.php index 7b2a8b973..335e1c165 100644 --- a/src/Psalm/Internal/Codebase/Analyzer.php +++ b/src/Psalm/Internal/Codebase/Analyzer.php @@ -1552,12 +1552,12 @@ class Analyzer $has_info = false; foreach ($issues as $issue) { - if ($issue->severity === 'error') { + if ($issue->severity === IssueData::SEVERITY_ERROR) { $has_error = true; break; } - if ($issue->severity === 'info') { + if ($issue->severity === IssueData::SEVERITY_INFO) { $has_info = true; } } diff --git a/src/Psalm/Issue/CodeIssue.php b/src/Psalm/Issue/CodeIssue.php index 08645794d..ce4fcbc46 100644 --- a/src/Psalm/Issue/CodeIssue.php +++ b/src/Psalm/Issue/CodeIssue.php @@ -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; diff --git a/src/Psalm/IssueBuffer.php b/src/Psalm/IssueBuffer.php index 0c40288a0..e30f87200 100644 --- a/src/Psalm/IssueBuffer.php +++ b/src/Psalm/IssueBuffer.php @@ -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); @@ -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(), diff --git a/src/Psalm/Plugin/Shepherd.php b/src/Psalm/Plugin/Shepherd.php index 73cbdac4a..bb0ba7bb1 100644 --- a/src/Psalm/Plugin/Shepherd.php +++ b/src/Psalm/Plugin/Shepherd.php @@ -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(); diff --git a/src/Psalm/Report/EmacsReport.php b/src/Psalm/Report/EmacsReport.php index d022fe5dc..c1cb008e6 100644 --- a/src/Psalm/Report/EmacsReport.php +++ b/src/Psalm/Report/EmacsReport.php @@ -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, diff --git a/src/Psalm/Report/GithubActionsReport.php b/src/Psalm/Report/GithubActionsReport.php index 71a7a0f6c..9d7c617f4 100644 --- a/src/Psalm/Report/GithubActionsReport.php +++ b/src/Psalm/Report/GithubActionsReport.php @@ -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"; diff --git a/src/Psalm/Report/TextReport.php b/src/Psalm/Report/TextReport.php index d2fa2382b..2ee578fdf 100644 --- a/src/Psalm/Report/TextReport.php +++ b/src/Psalm/Report/TextReport.php @@ -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"; diff --git a/tests/ByIssueLevelAndTypeReportTest.php b/tests/ByIssueLevelAndTypeReportTest.php index 28e495028..2b8eb7a55 100644 --- a/tests/ByIssueLevelAndTypeReportTest.php +++ b/tests/ByIssueLevelAndTypeReportTest.php @@ -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, diff --git a/tests/ErrorBaselineTest.php b/tests/ErrorBaselineTest.php index ac0e2cad4..3b4741f58 100644 --- a/tests/ErrorBaselineTest.php +++ b/tests/ErrorBaselineTest.php @@ -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', diff --git a/tests/IssueBufferTest.php b/tests/IssueBufferTest.php index bbf2add82..d167cf593 100644 --- a/tests/IssueBufferTest.php +++ b/tests/IssueBufferTest.php @@ -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", diff --git a/tests/ReportOutputTest.php b/tests/ReportOutputTest.php index 4c768484b..8864247ab 100644 --- a/tests/ReportOutputTest.php +++ b/tests/ReportOutputTest.php @@ -833,7 +833,7 @@ class ReportOutputTest extends TestCase { $issues_data = [ 22 => new IssueData( - 'info', + IssueData::SEVERITY_INFO, 15, 15, 'PossiblyUndefinedGlobalVariable',