Hey,

all our custom modules are prefixed by "aw24_". This results in namespaces similar to this:


/**
   * Set the ID of the assigned user entity.
   *
   * @param int $uid
   *   User ID to set.
   *
   * @return \Drupal\aw24_user\Entity\UserInterface
   *   The User ID.
   */
  public function setOwnerId($uid);

which in turn phpcs marks as error, suggesting instead:

Expected "\Drupal\aw_user\Entity\UserInterface" but found "\Drupal\aw24_user\Entity\UserInterface" for function return type

Drupal coding standards do forbid module names beginning with numbers, but not containing them.

I can prevent this error by altering FunctionCommentSniff.php::suggestType and adding "0-9" to the RegExp below

    public static function suggestType($type)
    {
        if (isset(static::$invalidTypes[$type]) === true) {
            return static::$invalidTypes[$type];
        }

        if ($type === '$this') {
            return $type;
        }

        $type = preg_replace('/[^a-zA-Z0-9_\\\[\]]/', '', $type);

        return $type;

    }

This would allow types beginning with / consisting solely of numbers though.

Comments

ChristianAdamski created an issue. See original summary.

  • klausi committed c36d0c6 on 8.x-2.x
    fix(FunctionCommentSniff): Allow numbers in data types for @param and @...

klausi credited klausi.

klausi credited klausi.

klausi’s picture

Status: Active » Fixed

Thanks for reporting! Committed a fix.

ChristianAdamski’s picture

Just a warning:

I think your fix does now correctly allow

function test22(MyInterface $a) {

but I think it would also allow

function 22test(MyInterface $a) {

which it shouldn't? Not sure though.

klausi’s picture

Yes, technically it does allow that, but the code would not be valid PHP. So you couldn't even use that code. Good enough for us :)

Status: Fixed » Closed (fixed)

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