1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Introduce and use IssueData constants for severity

they are not the same as Config::REPORT_* constants
This commit is contained in:
Alies Lapatsin 2023-05-31 12:38:15 +02:00
parent bebce06014
commit 174cd5c0fe
12 changed files with 40 additions and 30 deletions

View File

@ -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
*/

View File

@ -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;
}
}

View File

@ -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;

View File

@ -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(),

View File

@ -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();

View File

@ -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,

View File

@ -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";

View File

@ -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";

View File

@ -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,

View File

@ -187,7 +187,7 @@ bar&#13;
[
'sample/sample-file.php' => [
new IssueData(
'error',
IssueData::SEVERITY_ERROR,
0,
0,
'MixedAssignment',
@ -204,7 +204,7 @@ bar&#13;
0,
),
new IssueData(
'error',
IssueData::SEVERITY_ERROR,
0,
0,
'MixedAssignment',
@ -221,7 +221,7 @@ bar&#13;
0,
),
new IssueData(
'error',
IssueData::SEVERITY_ERROR,
0,
0,
'MixedAssignment',
@ -238,7 +238,7 @@ bar&#13;
0,
),
new IssueData(
'error',
IssueData::SEVERITY_ERROR,
0,
0,
'MixedOperand',
@ -274,7 +274,7 @@ bar&#13;
],
'sample/sample-file2.php' => [
new IssueData(
'error',
IssueData::SEVERITY_ERROR,
0,
0,
'MixedAssignment',
@ -291,7 +291,7 @@ bar&#13;
0,
),
new IssueData(
'error',
IssueData::SEVERITY_ERROR,
0,
0,
'MixedAssignment',
@ -308,7 +308,7 @@ bar&#13;
0,
),
new IssueData(
'error',
IssueData::SEVERITY_ERROR,
0,
0,
'TypeCoercion',
@ -410,7 +410,7 @@ bar&#13;
$newIssues = [
'sample/sample-file.php' => [
new IssueData(
'error',
IssueData::SEVERITY_ERROR,
0,
0,
'MixedAssignment',
@ -427,7 +427,7 @@ bar&#13;
0,
),
new IssueData(
'error',
IssueData::SEVERITY_ERROR,
0,
0,
'MixedAssignment',
@ -444,7 +444,7 @@ bar&#13;
0,
),
new IssueData(
'error',
IssueData::SEVERITY_ERROR,
0,
0,
'MixedOperand',
@ -461,7 +461,7 @@ bar&#13;
0,
),
new IssueData(
'error',
IssueData::SEVERITY_ERROR,
0,
0,
'MixedOperand',
@ -480,7 +480,7 @@ bar&#13;
],
'sample/sample-file2.php' => [
new IssueData(
'error',
IssueData::SEVERITY_ERROR,
0,
0,
'TypeCoercion',

View File

@ -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",

View File

@ -833,7 +833,7 @@ class ReportOutputTest extends TestCase
{
$issues_data = [
22 => new IssueData(
'info',
IssueData::SEVERITY_INFO,
15,
15,
'PossiblyUndefinedGlobalVariable',