diff --git a/rules/Php82/Rector/Class_/ReadOnlyClassRector.php b/rules/Php82/Rector/Class_/ReadOnlyClassRector.php index a7be21a5ec5..b43dfee3cae 100644 --- a/rules/Php82/Rector/Class_/ReadOnlyClassRector.php +++ b/rules/Php82/Rector/Class_/ReadOnlyClassRector.php @@ -144,6 +144,11 @@ private function hasNonTypedProperty(array $properties): bool private function shouldSkip(Class_ $class, Scope $scope): bool { + $classReflection = $scope->getClassReflection(); + if (! $classReflection instanceof ClassReflection) { + return true; + } + if ($this->shouldSkipClass($class)) { return true; } diff --git a/tests/Issues/ExtendsNotReadOnlyClass/ExtendsNotReadOnlyClassTest.php b/tests/Issues/ExtendsNotReadOnlyClass/ExtendsNotReadOnlyClassTest.php new file mode 100644 index 00000000000..7d717cfaa39 --- /dev/null +++ b/tests/Issues/ExtendsNotReadOnlyClass/ExtendsNotReadOnlyClassTest.php @@ -0,0 +1,28 @@ +doTestFile($filePath); + } + + public static function provideData(): Iterator + { + return self::yieldFilesFromDirectory(__DIR__ . '/Fixture'); + } + + public function provideConfigFilePath(): string + { + return __DIR__ . '/config/configured_rule.php'; + } +} diff --git a/tests/Issues/ExtendsNotReadOnlyClass/Fixture/fixture.php.inc b/tests/Issues/ExtendsNotReadOnlyClass/Fixture/fixture.php.inc new file mode 100644 index 00000000000..31e66b00344 --- /dev/null +++ b/tests/Issues/ExtendsNotReadOnlyClass/Fixture/fixture.php.inc @@ -0,0 +1,39 @@ +foo; + } +} + +?> +----- +foo; + } +} + +?> diff --git a/tests/Issues/ExtendsNotReadOnlyClass/Source/ParentIsNonReadOnlyClass.php b/tests/Issues/ExtendsNotReadOnlyClass/Source/ParentIsNonReadOnlyClass.php new file mode 100644 index 00000000000..8cca7094af3 --- /dev/null +++ b/tests/Issues/ExtendsNotReadOnlyClass/Source/ParentIsNonReadOnlyClass.php @@ -0,0 +1,9 @@ +rules([ + ReadOnlyPropertyRector::class, + FinalizeClassesWithoutChildrenRector::class, + ReadOnlyClassRector::class, + ]); +};