mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Merge pull request #8542 from gphargreaves/class-constant-named-class
Add check for class const with reserved word 'class'
This commit is contained in:
commit
52e96bea38
@ -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) {
|
||||
|
@ -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',
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user