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
Comment #5
klausiThanks for reporting! Committed a fix.
Comment #6
christianadamski commentedJust a warning:
I think your fix does now correctly allow
but I think it would also allow
which it shouldn't? Not sure though.
Comment #7
klausiYes, 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 :)