drupal-check icon indicating copy to clipboard operation
drupal-check copied to clipboard

Conflict with phpcs for hook implementations

Open andrewbelcher opened this issue 2 years ago • 1 comments

How is drupal-check installed? drupal-check is installed as a dependency to my project

Environment:

  • OS: DDEV
  • PHP Version: 8.2
  • Drupal core: 10.x.x

Describe the bug phpcs coding standards and drupal-check conflict with hook implementations. An example:

/**
 * Implements hook_entity_type_build().
 */
function mymodule_enttiy_type-build(array &$entity_types): void {
  // Do stuff....
}

This will pass phpcs coding standards, but will fail drupal-check with Function mymodule_entity_type_build() has parameter $entity_types with no value type specified in iterable type array.

The fix for phpstan is to use an @param \Drupal\Core\Entity\EntityTypeInterface[] $entity_types, but this then causes phpcs to fail with Hook implementations should not duplicate @param documentation.

It's worth noting that hook_entity_type_build already has the correct typehint.

Suggested fix Is there a way we can extend the phpdoc interpretation to follow Implements hook_HOOK_NAME(). in a similar way that {@inheritdoc} is followed for classes?

andrewbelcher avatar Aug 16 '23 09:08 andrewbelcher

Actually, just found https://github.com/mglaman/phpstan-drupal/issues/404 which I think is where this would actually be fixed...

andrewbelcher avatar Aug 16 '23 17:08 andrewbelcher