Skip to content

Commit

Permalink
Try with consitional logic
Browse files Browse the repository at this point in the history
  • Loading branch information
bbrala committed Jan 11, 2024
1 parent a1d3069 commit 806fdea
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Drupal8/Rector/Deprecation/EntityLoadRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,19 @@ public function refactor(Node $node): ?Node

$resetCache_method_name = new Node\Identifier('resetCache');


if (!class_exists('\PhpParser\Node\ArrayItem')) {
$arrayItems = [new Node\Expr\ArrayItem($entity_id->value)];
} else {
$arrayItems = [new \PhpParser\Node\ArrayItem($entity_id->value)];
}

$reset_args = [
// This creates a new argument that wraps the entity ID in an array.
new Node\Arg(new Node\Expr\Array_([new \PhpParser\Node\ArrayItem($entity_id->value)])),
new Node\Arg(new Node\Expr\Array_($arrayItems)),
];


$entity_load_reset_node = new Node\Expr\MethodCall($getStorage_node,
$resetCache_method_name, $reset_args);

Expand Down

0 comments on commit 806fdea

Please sign in to comment.