Problem/Motivation

While running phpcs for my code i get the error :

[exec] 117 | ERROR | [x] Calling class constructors must always include
[exec] | | parentheses

The code that fails however does have parenthesis.

Line 117 is "new PublishedNodesValidator(),

  /**
   * Return the validators.
   *
   * @return ValidatorInterface[]
   *   The validators.
   */
  public function getValidators(): array {
    return [
      new PublishedNodesValidator(),
      new MinimumNodesValidator($this->nrOfArticles),
      new AccessibleOnCurrentDomainValidator($this->sectionService),
    ];
  }

The problem can be circumvented in 2 ways
1) Remove the ": array part"
2) Place code before the return something like "$test=1;". Rewriting the code so i first assign the new to variables and add those variables to the array works as well but is the same idea as just adding the "$test=1;" part.

Also because of this problem PHPCBF acts strange as it keeps adding parenthesis resulting in

      new PublishedNodesValidator()()()()()()()()()()()()()(),

Comments

melvinlouwerse created an issue. See original summary.

  • klausi committed f4ae908 on 8.x-2.x
    fix(ClassCreateInstanceSniff): Fix false positive for PHP 7 return type...

  • klausi committed bdcefa4 on 8.x-2.x
    fix(ClassCreateInstanceSniff): Improve missing parenthesis detection...
klausi’s picture

Version: 8.x-2.10 » 8.x-2.x-dev
Status: Active » Fixed

Pushed a fix, thanks for reporting!

klausi’s picture

Assigning credits

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.