diff --git a/docs/running_psalm/issues/MissingClassConstType.md b/docs/running_psalm/issues/MissingClassConstType.md index cadafbd2b55..c4fa9049fc6 100644 --- a/docs/running_psalm/issues/MissingClassConstType.md +++ b/docs/running_psalm/issues/MissingClassConstType.md @@ -6,7 +6,7 @@ Emitted when a class constant doesn't have a declared type. 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( @@ -1429,7 +1432,7 @@ private function visitClassConstDeclaration( $storage->name, $const->name->name, ), - new CodeLocation($this->file_scanner, $stmt), + new CodeLocation($this->file_scanner, $const), ), $suppressed_issues, ); diff --git a/tests/DocumentationTest.php b/tests/DocumentationTest.php index aff06fde78b..95b2ad3c1b8 100644 --- a/tests/DocumentationTest.php +++ b/tests/DocumentationTest.php @@ -316,6 +316,7 @@ public function providerInvalidCodeParse(): array case 'InvalidOverride': case 'MissingOverrideAttribute': + case 'MissingClassConstType': $php_version = '8.3'; break; } diff --git a/tests/MissingClassConstTypeTest.php b/tests/MissingClassConstTypeTest.php index a1a8402bdaa..de413050fdb 100644 --- a/tests/MissingClassConstTypeTest.php +++ b/tests/MissingClassConstTypeTest.php @@ -4,6 +4,7 @@ namespace Psalm\Tests; +use Psalm\Issue\MissingClassConstType; use Psalm\Tests\Traits\InvalidCodeAnalysisTestTrait; use Psalm\Tests\Traits\ValidCodeAnalysisTestTrait; @@ -33,6 +34,8 @@ class A { public const B = 0; } PHP, + 'assertions' => [], + 'ignored_issues' => [], 'php_version' => '8.2', ], ]; @@ -48,7 +51,7 @@ class A { public const B = 0; } PHP, - 'error_message' => 'MissingClassConstType', + 'error_message' => MissingClassConstType::getIssueType(), 'error_levels' => [], 'php_version' => '8.3', ],