Skip to content

Commit

Permalink
Be more defensive while refactoring entitymanager
Browse files Browse the repository at this point in the history
  • Loading branch information
bbrala committed Nov 26, 2023
1 parent 8c0fa4e commit c66ee9f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
10 changes: 6 additions & 4 deletions src/Drupal8/Rector/Deprecation/EntityManagerRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use DrupalRector\Services\AddCommentService;
use PhpParser\Node;
use PhpParser\NodeDumper;
use PHPStan\Analyser\Scope;
use Rector\Core\Exception\ShouldNotHappenException;
use Rector\Core\Rector\AbstractRector;
Expand Down Expand Up @@ -108,6 +109,9 @@ public function refactor(Node $node): ?Node
$expr = $this->findInstanceByNameInAssign($node->expr, Node\Expr\CallLike::class, 'entityManager');
if (!is_null($expr)) {
$expr = $this->refactorExpression($expr, $node);
if (is_null($expr)) {
return null;
}
$node->expr = $this->replaceInstanceByNameInAssign($node->expr, $expr, Node\Expr\CallLike::class, 'entityManager');

return $node;
Expand Down Expand Up @@ -152,10 +156,8 @@ public function findInstanceByNameInAssign(Node\Expr\Assign $assign, string $cla
}

// Find the relevant class with name in the chain.
while (isset($node->var) && !($node->var instanceof $class && $this->getName($node->var->name) !== $name)) {
$node = $node->var;
++$depth;
if ($node instanceof $class && $this->getName($node->name)) {
while (isset($node->var) && $node->var !== null && !($node->var instanceof $class && isset($node->var->name) && $this->getName($node->var->name) !== $name)) {
if ($node instanceof $class && isset($node->name) && $this->getName($node->name)) {
$node->setAttribute(self::class, $depth);

return $node;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,6 @@ class AcquiaContentHubSiteCommands extends DrushCommands {
?>
-----
<?php
<?php

namespace Drupal\acquia_contenthub\Commands;

Expand Down

0 comments on commit c66ee9f

Please sign in to comment.