1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 20:34:47 +01:00

Add check for const with reserved word class

This commit is contained in:
Gregory Hargreaves 2022-10-07 09:44:10 +01:00
parent b6ddcdf3e5
commit 41a6afda32
2 changed files with 22 additions and 0 deletions

View File

@ -508,6 +508,16 @@ class ClassAnalyzer extends ClassLikeAnalyzer
$member_stmts[] = $stmt;
foreach ($stmt->consts as $const) {
if ($const->name->toLowerString() === 'class') {
IssueBuffer::maybeAdd(
new ReservedWord(
'A class constant cannot be named \'class\'',
new CodeLocation($this, $this->class),
$this->fq_class_name
)
);
}
$const_id = strtolower($this->fq_class_name) . '::' . $const->name;
foreach ($codebase->class_constants_to_rename as $original_const_id => $new_const_name) {

View File

@ -925,6 +925,18 @@ class ClassTest extends TestCase
',
'error_message' => 'InvalidTraversableImplementation',
],
'cannotNameClassConstantClass' => [
'<?php
class Foo
{
/** @var class-string<Bar> */
protected const CLASS = Bar::class;
}
class Bar {}
',
'error_message' => 'ReservedWord',
]
];
}
}