Skip to content

Commit 489ce47

Browse files
committed
[ci-review] Rector Rectify
1 parent 91a1975 commit 489ce47

File tree

1 file changed

+29
-13
lines changed

1 file changed

+29
-13
lines changed

rules/DowngradePhp80/Rector/NullsafeMethodCall/DowngradeNullsafeToTernaryOperatorRector.php

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -68,26 +68,42 @@ public function refactor(Node $node): ?Ternary
6868
$nullsafeVariable = $this->createNullsafeVariable();
6969

7070
$assign = new Assign($nullsafeVariable, $node->var->var);
71-
7271
if ($node instanceof MethodCall) {
7372
if ($node->var instanceof NullsafeMethodCall) {
74-
$methodCallOrPropertyFetch = new MethodCall(new MethodCall($nullsafeVariable, $node->var->name, $node->var->args), $node->name, $node->args);
75-
return new Ternary($assign, $methodCallOrPropertyFetch, $this->nodeFactory->createNull());
76-
} else {
77-
$methodCallOrPropertyFetch = new MethodCall(new PropertyFetch($nullsafeVariable, $node->var->name), $node->name, $node->args);
78-
return new Ternary($assign, $methodCallOrPropertyFetch, $this->nodeFactory->createNull());
79-
}
80-
} else {
81-
if ($node->var instanceof NullsafeMethodCall) {
82-
$methodCallOrPropertyFetch = new PropertyFetch(new MethodCall($nullsafeVariable, $node->var->name, $node->var->args), $node->name);
83-
return new Ternary($assign, $methodCallOrPropertyFetch, $this->nodeFactory->createNull());
84-
} else {
85-
$methodCallOrPropertyFetch = new PropertyFetch(new PropertyFetch($nullsafeVariable, $node->var->name), $node->name);
73+
$methodCallOrPropertyFetch = new MethodCall(new MethodCall(
74+
$nullsafeVariable,
75+
$node->var->name,
76+
$node->var->args
77+
), $node->name, $node->args);
8678
return new Ternary($assign, $methodCallOrPropertyFetch, $this->nodeFactory->createNull());
8779
}
80+
$methodCallOrPropertyFetch = new MethodCall(new PropertyFetch(
81+
$nullsafeVariable,
82+
$node->var->name
83+
), $node->name, $node->args);
84+
return new Ternary($assign, $methodCallOrPropertyFetch, $this->nodeFactory->createNull());
85+
}
86+
87+
if ($node->var instanceof NullsafeMethodCall) {
88+
$methodCallOrPropertyFetch = new PropertyFetch(new MethodCall(
89+
$nullsafeVariable,
90+
$node->var->name,
91+
$node->var->args
92+
), $node->name);
93+
return new Ternary($assign, $methodCallOrPropertyFetch, $this->nodeFactory->createNull());
8894
}
8995

96+
$methodCallOrPropertyFetch = new PropertyFetch(new PropertyFetch(
97+
$nullsafeVariable,
98+
$node->var->name
99+
), $node->name);
90100
return new Ternary($assign, $methodCallOrPropertyFetch, $this->nodeFactory->createNull());
101+
102+
return new Ternary(
103+
$assign,
104+
$methodCallOrPropertyFetch,
105+
$this->nodeFactory->createNull()
106+
);
91107
}
92108

93109
return null;

0 commit comments

Comments
 (0)