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:
parent
b6ddcdf3e5
commit
41a6afda32
@ -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