Skip to content

Commit

Permalink
MissingClassConstType
Browse files Browse the repository at this point in the history
  • Loading branch information
jack-worman committed Mar 14, 2024
1 parent ab9570f commit 97490d3
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
4 changes: 2 additions & 2 deletions docs/running_psalm/issues/MissingClassConstType.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Emitted when a class constant doesn't have a declared type.
<?php

class A {
private const B = 0;
public const B = 0;
}
```

Expand All @@ -16,6 +16,6 @@ Correct with:
<?php

class A {
private const int B = 0;
public const int B = 0;
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -1421,15 +1421,18 @@ private function visitClassConstDeclaration(
);


if ($this->codebase->analysis_php_version_id >= 8_03_00) {
if (
$this->codebase->analysis_php_version_id >= 8_03_00
&& $stmt->type === null
) {
IssueBuffer::maybeAdd(
new MissingClassConstType(
sprintf(
'Class constant "%s::%s" should have a declared type.',
$storage->name,
$const->name->name,
),
new CodeLocation($this->file_scanner, $stmt),
new CodeLocation($this->file_scanner, $const),
),
$suppressed_issues,
);
Expand Down
1 change: 1 addition & 0 deletions tests/DocumentationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ public function providerInvalidCodeParse(): array

case 'InvalidOverride':
case 'MissingOverrideAttribute':
case 'MissingClassConstType':
$php_version = '8.3';
break;
}
Expand Down
5 changes: 4 additions & 1 deletion tests/MissingClassConstTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Psalm\Tests;

use Psalm\Issue\MissingClassConstType;
use Psalm\Tests\Traits\InvalidCodeAnalysisTestTrait;
use Psalm\Tests\Traits\ValidCodeAnalysisTestTrait;

Expand Down Expand Up @@ -33,6 +34,8 @@ class A {
public const B = 0;
}
PHP,
'assertions' => [],
'ignored_issues' => [],
'php_version' => '8.2',
],
];
Expand All @@ -48,7 +51,7 @@ class A {
public const B = 0;
}
PHP,
'error_message' => 'MissingClassConstType',
'error_message' => MissingClassConstType::getIssueType(),
'error_levels' => [],
'php_version' => '8.3',
],
Expand Down

0 comments on commit 97490d3

Please sign in to comment.