From 46141f648e620c38de81ffa89d537e93cbe5eaa2 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Thu, 30 Jul 2026 01:04:27 +0200 Subject: [PATCH 1/2] [DeadCode] Keep empty __construct() in anonymous class that extends parent on RemoveEmptyClassMethodRector --- ...ous_class_construct_without_parent.php.inc | 27 +++++++++++++++++++ ...nymous_class_construct_with_parent.php.inc | 16 +++++++++++ .../RemoveEmptyClassMethodRector.php | 10 +++++++ 3 files changed, 53 insertions(+) create mode 100644 rules-tests/DeadCode/Rector/ClassMethod/RemoveEmptyClassMethodRector/Fixture/removed_anonymous_class_construct_without_parent.php.inc create mode 100644 rules-tests/DeadCode/Rector/ClassMethod/RemoveEmptyClassMethodRector/Fixture/skip_anonymous_class_construct_with_parent.php.inc diff --git a/rules-tests/DeadCode/Rector/ClassMethod/RemoveEmptyClassMethodRector/Fixture/removed_anonymous_class_construct_without_parent.php.inc b/rules-tests/DeadCode/Rector/ClassMethod/RemoveEmptyClassMethodRector/Fixture/removed_anonymous_class_construct_without_parent.php.inc new file mode 100644 index 00000000000..1013f3123b6 --- /dev/null +++ b/rules-tests/DeadCode/Rector/ClassMethod/RemoveEmptyClassMethodRector/Fixture/removed_anonymous_class_construct_without_parent.php.inc @@ -0,0 +1,27 @@ + +----- + diff --git a/rules-tests/DeadCode/Rector/ClassMethod/RemoveEmptyClassMethodRector/Fixture/skip_anonymous_class_construct_with_parent.php.inc b/rules-tests/DeadCode/Rector/ClassMethod/RemoveEmptyClassMethodRector/Fixture/skip_anonymous_class_construct_with_parent.php.inc new file mode 100644 index 00000000000..f5dbe64e0b5 --- /dev/null +++ b/rules-tests/DeadCode/Rector/ClassMethod/RemoveEmptyClassMethodRector/Fixture/skip_anonymous_class_construct_with_parent.php.inc @@ -0,0 +1,16 @@ + diff --git a/rules/DeadCode/Rector/ClassMethod/RemoveEmptyClassMethodRector.php b/rules/DeadCode/Rector/ClassMethod/RemoveEmptyClassMethodRector.php index 6557fd579c4..d7ef32dab1f 100644 --- a/rules/DeadCode/Rector/ClassMethod/RemoveEmptyClassMethodRector.php +++ b/rules/DeadCode/Rector/ClassMethod/RemoveEmptyClassMethodRector.php @@ -6,6 +6,7 @@ use PhpParser\Comment\Doc; use PhpParser\Node; +use PhpParser\Node\Name; use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\ClassMethod; use PHPStan\PhpDocParser\Ast\PhpDoc\DeprecatedTagValueNode; @@ -142,6 +143,15 @@ private function shouldSkipClassMethod(Class_ $class, ClassMethod $classMethod): return true; } + // anonymous class extending a parent uses empty constructor on purpose, + // to avoid parent constructor being invoked + if ($class->isAnonymous() && $class->extends instanceof Name && $this->isName( + $classMethod, + MethodName::CONSTRUCT + )) { + return true; + } + if ($this->classMethodManipulator->hasParentMethodOrInterfaceMethod($class, $classMethod->name->toString())) { return true; } From f4c4f1eb946ee151fb9e12fa9624626d9758c2d8 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Wed, 29 Jul 2026 23:06:03 +0000 Subject: [PATCH 2/2] [ci-review] Rector Rectify --- src/FileSystem/FilePathHelper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/FileSystem/FilePathHelper.php b/src/FileSystem/FilePathHelper.php index 656784226ad..d4d01ce3a5a 100644 --- a/src/FileSystem/FilePathHelper.php +++ b/src/FileSystem/FilePathHelper.php @@ -56,7 +56,7 @@ public function normalizePathAndSchema(string $originalPath): string $path = $originalPath; } - $normalizedPath = PathNormalizer::normalize((string) $path); + $normalizedPath = PathNormalizer::normalize($path); $path = Strings::replace($normalizedPath, self::TWO_AND_MORE_SLASHES_REGEX, '/'); $pathRoot = str_starts_with($path, '/') ? $directorySeparator : '';