From 23108b00facadc9290f9fa2ff9080bbc164da09c Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Mon, 23 Nov 2026 22:48:52 +0100 Subject: [PATCH] [Php83] Require parent class in RemoveGetClassGetParentClassNoArgsRector --- .../Fixture/fixture_get_parent_class.php.inc | 8 +++++-- ...ip_get_parent_class_without_parent.php.inc | 11 +++++++++ .../Fixture/skip_outside_class.php.inc | 9 ++++++++ .../Source/SomeParentClass.php | 9 ++++++++ ...moveGetClassGetParentClassNoArgsRector.php | 23 ++++++++++++++++--- 5 files changed, 55 insertions(+), 5 deletions(-) create mode 100644 rules-tests/Php83/Rector/FuncCall/RemoveGetClassGetParentClassNoArgsRector/Fixture/skip_get_parent_class_without_parent.php.inc create mode 100644 rules-tests/Php83/Rector/FuncCall/RemoveGetClassGetParentClassNoArgsRector/Fixture/skip_outside_class.php.inc create mode 100644 rules-tests/Php83/Rector/FuncCall/RemoveGetClassGetParentClassNoArgsRector/Source/SomeParentClass.php diff --git a/rules-tests/Php83/Rector/FuncCall/RemoveGetClassGetParentClassNoArgsRector/Fixture/fixture_get_parent_class.php.inc b/rules-tests/Php83/Rector/FuncCall/RemoveGetClassGetParentClassNoArgsRector/Fixture/fixture_get_parent_class.php.inc index daf6b9e8d83..0b1eef9f40a 100644 --- a/rules-tests/Php83/Rector/FuncCall/RemoveGetClassGetParentClassNoArgsRector/Fixture/fixture_get_parent_class.php.inc +++ b/rules-tests/Php83/Rector/FuncCall/RemoveGetClassGetParentClassNoArgsRector/Fixture/fixture_get_parent_class.php.inc @@ -2,7 +2,9 @@ namespace Rector\Tests\Php83\Rector\FuncCall\RemoveGetClassGetParentClassNoArgsRector\Fixture; -class Fixture +use Rector\Tests\Php83\Rector\FuncCall\RemoveGetClassGetParentClassNoArgsRector\Source\SomeParentClass; + +class Fixture extends SomeParentClass { public function test() { @@ -16,7 +18,9 @@ class Fixture namespace Rector\Tests\Php83\Rector\FuncCall\RemoveGetClassGetParentClassNoArgsRector\Fixture; -class Fixture +use Rector\Tests\Php83\Rector\FuncCall\RemoveGetClassGetParentClassNoArgsRector\Source\SomeParentClass; + +class Fixture extends SomeParentClass { public function test() { diff --git a/rules-tests/Php83/Rector/FuncCall/RemoveGetClassGetParentClassNoArgsRector/Fixture/skip_get_parent_class_without_parent.php.inc b/rules-tests/Php83/Rector/FuncCall/RemoveGetClassGetParentClassNoArgsRector/Fixture/skip_get_parent_class_without_parent.php.inc new file mode 100644 index 00000000000..5c6fce3e09e --- /dev/null +++ b/rules-tests/Php83/Rector/FuncCall/RemoveGetClassGetParentClassNoArgsRector/Fixture/skip_get_parent_class_without_parent.php.inc @@ -0,0 +1,11 @@ +reflectionResolver->resolveClassReflection($node); + if (! $classReflection instanceof ClassReflection) { + return null; + } + + // parent::class is a fatal error in a class without parent + if ($target === 'parent' && ! $classReflection->getParentClass() instanceof ClassReflection) { + return null; } - return null; + return new ClassConstFetch(new Name([$target]), new VarLikeIdentifier('class')); } public function provideMinPhpVersion(): int