Skip to content

Commit 256004a

Browse files
committed
restore fixture
1 parent bba767d commit 256004a

File tree

4 files changed

+54
-4
lines changed

4 files changed

+54
-4
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
class SomeParentA
4+
{
5+
public function SomeParentA()
6+
{
7+
}
8+
}
9+
10+
final class SomeChildB extends SomeParentA
11+
{
12+
public function SomeChildB() {
13+
$this->SomeParentA();
14+
}
15+
}
16+
17+
?>
18+
-----
19+
<?php
20+
21+
class SomeParentA
22+
{
23+
public function __construct()
24+
{
25+
}
26+
}
27+
28+
final class SomeChildB extends SomeParentA
29+
{
30+
public function __construct() {
31+
\SomeParentA::__construct();
32+
}
33+
}
34+
35+
?>

rules-tests/Php70/Rector/ClassMethod/Php4ConstructorRector/Fixture/parent_constructor_call.php.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ final class SomeChildB extends ParentClass
1616
{
1717
public function __construct()
1818
{
19-
parent::__construct();
19+
\ParentClass::__construct();
2020
}
2121
}
2222

rules/Php70/NodeAnalyzer/MethodCallNameAnalyzer.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66

77
use PhpParser\Node\Expr;
88
use PhpParser\Node\Expr\MethodCall;
9+
use PhpParser\Node\Expr\Variable;
910
use PhpParser\Node\Identifier;
1011
use PhpParser\Node\Name;
1112
use PhpParser\Node\Stmt\Class_;
13+
use PhpParser\Node\Stmt\ClassMethod;
1214

1315
final class MethodCallNameAnalyzer
1416
{
@@ -18,7 +20,7 @@ public function isLocalMethodCallNamed(Expr $expr, string $desiredMethodName): b
1820
return false;
1921
}
2022

21-
if (! $expr->var instanceof Expr\Variable) {
23+
if (! $expr->var instanceof Variable) {
2224
return false;
2325
}
2426

@@ -40,7 +42,7 @@ public function isParentMethodCall(Class_ $class, Expr $expr): bool
4042
}
4143

4244
$parentClassName = $class->extends->toString();
43-
if ($class->getMethod($parentClassName)) {
45+
if ($class->getMethod($parentClassName) instanceof ClassMethod) {
4446
return false;
4547
}
4648

rules/Php70/Rector/ClassMethod/Php4ConstructorRector.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use PhpParser\Node\Expr\StaticCall;
1010
use PhpParser\Node\Identifier;
1111
use PhpParser\Node\Name;
12+
use PhpParser\Node\Name\FullyQualified;
1213
use PhpParser\Node\Stmt\Class_;
1314
use PhpParser\Node\Stmt\ClassMethod;
1415
use PhpParser\Node\Stmt\Expression;
@@ -137,7 +138,10 @@ public function refactor(Node $node): Class_|null
137138
/** @var MethodCall $expr */
138139
$expr = $classMethodStmt->expr;
139140

140-
$classMethodStmt->expr = new StaticCall(new Name(ObjectReference::PARENT), new Identifier(
141+
/** @var string $parentClassName */
142+
$parentClassName = $this->getParentClassName($node);
143+
144+
$classMethodStmt->expr = new StaticCall(new FullyQualified($parentClassName), new Identifier(
141145
MethodName::CONSTRUCT
142146
), $expr->args);
143147
}
@@ -194,4 +198,13 @@ private function processParentPhp4ConstructCall(StaticCall $staticCall, Scope $s
194198

195199
$staticCall->name = new Identifier(MethodName::CONSTRUCT);
196200
}
201+
202+
private function getParentClassName(Class_ $class): ?string
203+
{
204+
if (! $class->extends instanceof \PhpParser\Node) {
205+
return null;
206+
}
207+
208+
return $class->extends->toString();
209+
}
197210
}

0 commit comments

Comments
 (0)