Skip to content

Conflict with phpcs for hook implementations #301

@andrewbelcher

Description

@andrewbelcher

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions