From 6a50019da60c66731789f924e21e4778b37501f2 Mon Sep 17 00:00:00 2001 From: Hendrik Mennen Date: Tue, 17 Nov 2026 10:13:47 +0100 Subject: [PATCH] [Core] Skip classes unknown to reflection instead of crashing in fetchClassLikeReflection A file with legacy syntax that PHPStan cannot parse, e.g. $value{0}, makes its classes unknown to the reflection provider while Rector still parses it with its own PHP 7.0 parser. Rules using fetchClassLikeReflection() threw 'Class should be known at this point' and Rector aborted the whole file, so rules like CurlyToSquareBracketArrayStringRector never ran on it. --- .../skip_class_unknown_to_reflection.php.inc | 14 ++++++++++++++ src/Rector/AbstractRector.php | 3 ++- 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 rules-tests/Php70/Rector/ClassMethod/Php4ConstructorRector/Fixture/skip_class_unknown_to_reflection.php.inc diff --git a/rules-tests/Php70/Rector/ClassMethod/Php4ConstructorRector/Fixture/skip_class_unknown_to_reflection.php.inc b/rules-tests/Php70/Rector/ClassMethod/Php4ConstructorRector/Fixture/skip_class_unknown_to_reflection.php.inc new file mode 100644 index 00000000000..8868a74c668 --- /dev/null +++ b/rules-tests/Php70/Rector/ClassMethod/Php4ConstructorRector/Fixture/skip_class_unknown_to_reflection.php.inc @@ -0,0 +1,14 @@ +reflectionProvider->hasClass($className)) { - throw new ShouldNotHappenException(sprintf('Class "%s" should be known at this point', $className)); + return null; } return $this->reflectionProvider->getClass($className);