From fe595348de4f6df9ef7acbe31819fb8b451af444 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Thu, 28 Nov 2024 17:13:03 +0700 Subject: [PATCH 1/2] [Php70] Do not replace if method exists in current method on call same method with parent on Php4ConstructorRector --- .../Fixture/method_call_method_exists.php.inc | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 rules-tests/Php70/Rector/ClassMethod/Php4ConstructorRector/Fixture/method_call_method_exists.php.inc diff --git a/rules-tests/Php70/Rector/ClassMethod/Php4ConstructorRector/Fixture/method_call_method_exists.php.inc b/rules-tests/Php70/Rector/ClassMethod/Php4ConstructorRector/Fixture/method_call_method_exists.php.inc new file mode 100644 index 00000000000..6367edb761d --- /dev/null +++ b/rules-tests/Php70/Rector/ClassMethod/Php4ConstructorRector/Fixture/method_call_method_exists.php.inc @@ -0,0 +1,43 @@ +SomeParentA2(); + } + + public function SomeParentA2() + { + } +} + +?> +----- +SomeParentA2(); + } + + public function SomeParentA2() + { + } +} + +?> From b9af9942105d9b8d6fc9bb822d5085798e8ab367 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Thu, 28 Nov 2024 17:15:30 +0700 Subject: [PATCH 2/2] fix --- rules/Php70/Rector/ClassMethod/Php4ConstructorRector.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rules/Php70/Rector/ClassMethod/Php4ConstructorRector.php b/rules/Php70/Rector/ClassMethod/Php4ConstructorRector.php index 62e07910a22..611f75eab58 100644 --- a/rules/Php70/Rector/ClassMethod/Php4ConstructorRector.php +++ b/rules/Php70/Rector/ClassMethod/Php4ConstructorRector.php @@ -132,7 +132,7 @@ public function refactor(Node $node): Class_|null unset($node->stmts[$stmtKey]); } - if ($this->isLocalMethodCallNamed($classMethodStmt->expr, $parentClassName)) { + if ($this->isLocalMethodCallNamed($classMethodStmt->expr, $parentClassName) && ! $node->getMethod($parentClassName) instanceof ClassMethod) { /** @var MethodCall $expr */ $expr = $classMethodStmt->expr; $classMethodStmt->expr = new StaticCall(new FullyQualified($parentClassName), new Identifier(MethodName::CONSTRUCT), $expr->args);