Skip to content

Commit c0fd4bf

Browse files
committed
remove array item scope, as handled in array
1 parent eafa741 commit c0fd4bf

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

rules/Php73/Rector/FuncCall/JsonThrowOnErrorRector.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use PhpParser\Node;
88
use PhpParser\Node\Arg;
99
use PhpParser\Node\Expr;
10+
use PhpParser\Node\Expr\BinaryOp\BitwiseOr;
1011
use PhpParser\Node\Expr\ConstFetch;
1112
use PhpParser\Node\Expr\FuncCall;
1213
use PhpParser\Node\Identifier;
@@ -26,9 +27,10 @@
2627
*/
2728
final class JsonThrowOnErrorRector extends AbstractRector implements MinPhpVersionInterface
2829
{
29-
private bool $hasChanged = false;
3030
private const array FLAGS = ['JSON_THROW_ON_ERROR'];
3131

32+
private bool $hasChanged = false;
33+
3234
public function __construct(
3335
private readonly ValueResolver $valueResolver,
3436
private readonly BetterNodeFinder $betterNodeFinder
@@ -140,11 +142,13 @@ private function processJsonEncode(FuncCall $funcCall): FuncCall
140142
$arg = $funcCall->args[1];
141143
$flags = $this->getFlags($arg);
142144
}
145+
143146
$newArg = $this->getArgWithFlags($flags);
144147
if ($newArg instanceof Arg) {
145148
$this->hasChanged = true;
146149
$funcCall->args[1] = $newArg;
147150
}
151+
148152
return $funcCall;
149153
}
150154

@@ -171,6 +175,7 @@ private function processJsonDecode(FuncCall $funcCall): FuncCall
171175
$this->hasChanged = true;
172176
$funcCall->args[3] = $newArg;
173177
}
178+
174179
return $funcCall;
175180
}
176181

@@ -213,10 +218,11 @@ private function getFlags(Expr|Arg $arg, array $flags = []): array
213218
}
214219

215220
// Multiple flags: FLAG_A | FLAG_B | FLAG_C
216-
if ($arg instanceof Node\Expr\BinaryOp\BitwiseOr) {
221+
if ($arg instanceof BitwiseOr) {
217222
$flags = $this->getFlags($arg->left, $flags);
218223
$flags = $this->getFlags($arg->right, $flags);
219224
}
225+
220226
return array_values(array_unique($flags)); // array_unique in case the same flag is written multiple times
221227
}
222228

@@ -230,18 +236,17 @@ private function getArgWithFlags(array $flags): ?Arg
230236
if ($originalCount === count($flags)) {
231237
return null;
232238
}
239+
233240
// Single flag
234241
if (count($flags) === 1) {
235242
return new Arg($this->createConstFetch($flags[0]));
236243
}
244+
237245
// Build FLAG_A | FLAG_B | FLAG_C
238246
$expr = $this->createConstFetch(array_shift($flags));
239247

240248
foreach ($flags as $flag) {
241-
$expr = new Node\Expr\BinaryOp\BitwiseOr(
242-
$expr,
243-
$this->createConstFetch($flag)
244-
);
249+
$expr = new BitwiseOr($expr, $this->createConstFetch($flag));
245250
}
246251

247252
return new Arg($expr);

src/NodeTypeResolver/PHPStan/Scope/PHPStanNodeScopeResolver.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -333,11 +333,6 @@ public function processNodes(
333333
return;
334334
}
335335

336-
if ($node instanceof ArrayItem) {
337-
$this->processArrayItem($node, $mutatingScope);
338-
return;
339-
}
340-
341336
if ($node instanceof NullableType) {
342337
$node->type->setAttribute(AttributeKey::SCOPE, $mutatingScope);
343338
return;

0 commit comments

Comments
 (0)