Error produced for some cases of using new keyword

Created on 15 November 2023, over 1 year ago
Updated 10 January 2024, over 1 year ago

Drupal version

Drupal 9.5.11

Drupal Rector version

palantirnet/drupal-rector version: 0.18.0
rector/rector version: 0.18.8

Problem / Motivation

For this php code in a views filter plugin.

  public function query() {
    $this->ensureMyTable();
    $field = $this->tableAlias . '.' . $this->realField;
    $in = $this->operator == self::EQUAL ? 'IN' : 'NOT IN';
    $condition = (new Condition('AND'))
      ->condition($field, modulename_get_types(), $in);
    $this->query->addWhere($this->options['group'], $condition);
  }

I am getting this error

[ERROR] Could not process "src/modules/modulename/src/Plugin/views/filter/filename.php" file, due to:
"System error: "Rector\Core\Rector\AbstractRector::getName(): Argument #1 ($node) must be of type
PhpParser\Node, null given, called in
vendor/palantirnet/drupal-rector/src/Rector/Deprecation/EntityManagerRector.php146"
Run Rector with "--debug" option and post the report here: https://github.com/rectorphp/rector/issues/new". On line: 190

If I change line 146 from

        while (isset($node->var) && !($node->var instanceof $class &&  $this->getName($node->var->name) !== $name)) {

to

        while (isset($node->var) && !($node->var instanceof $class && (empty($node->var->name) ? '' : $this->getName($node->var->name)) !== $name)) {

Then it does not error.

I can provide other failing code examples like in a hook_user_view_alter()

  $account = \Drupal::currentUser();
  /** @var  \Drupal\Core\Access\AccessResult $access_check */
  $access_check = (new CommentAccessCheck())->access($account);
πŸ› Bug report
Status

Fixed

Component

Code

Created by

πŸ‡¬πŸ‡§United Kingdom somersoft

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024