Ignore specifc sniffs when adding additional parameters to interface methods

Created on 23 June 2025, about 2 months ago

Problem/Motivation

The documentation for how to how to add additional parameters to interface methods uses 'phpcs: disable'.

The doc was initially changed in ๐ŸŒฑ Document how to add additional parameters to interface methods Fixed and later work in ๐Ÿ› Fix PHPStan arguments.count error Active

Steps to reproduce

Proposed resolution

Ignore only the specific sniffs needed, not all sniffs.
Change the example in 2 at Step 1: Prepare the new signature โ†’

current text

    * phpcs:disable Drupal.Commenting
    * @todo Uncomment new method parameters before drupal:11.0.0.
    * @see https://www.drupal.org/project/drupal/issues/3354672
    *
    * @param BazInterface $baz
    *   Documentation for parameter $baz.
    * phpcs:enable

proposed text

    * phpcs:ignore Drupal.Commenting.DocComment.TagGroupSpacing
    * @todo Uncomment new method parameters before drupal:11.0.0.
    * @see https://www.drupal.org/project/drupal/issues/3354672
    * phpcs:ignore Drupal.Commenting.FunctionComment.ParamNameNoMatch
    * @param BazInterface $baz
    *   Documentation for parameter $baz.

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

๐Ÿ“Œ Task
Status

Active

Version

11.0 ๐Ÿ”ฅ

Component

base system

Created by

๐Ÿ‡ณ๐Ÿ‡ฟNew Zealand quietone

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @quietone
  • First commit to issue fork.
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia immaculatexavier

    I've updated Step 2: Prepare the new signature in the documentation as part of this change. Specifically, I replaced the broad phpcs:disable Drupal.Commenting with targeted phpcs:ignore annotations for:

    Drupal.Commenting.DocComment.TagGroupSpacing

    Drupal.Commenting.FunctionComment.ParamNameNoMatch

    This ensures that we only suppress the necessary sniffs and maintain all other coding standards. The change is in line with the recommendations discussed in #3531685 Proposed Resolution

    https://www.drupal.org/about/core/policies/core-change-policies/how-to-d... โ†’

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States xjm

    I've actually gone further in ๐Ÿ› Fix PHPStan arguments.count error Active and proposed that we change the standard to move the @todo and @see to the correct part of the docblock. This achieves several things:

    1. It has better readability.
    2. It follows our existing documentation standards.
    3. It allows us to remove an entire phpcs:ignore from every single parameter and typehint addition of this sort.
    4. It allows for the possibility of multiple parameters being added to a method, and for listing them clearly for the developer.

    Here's an example from that issue:

      /**
       * Gets sorted plugin definitions.
       *
       * @param array[]|null $definitions
       *   (optional) The plugin definitions to sort. If omitted, all plugin
       *   definitions are used.
       * phpcs:ignore Drupal.Commenting.FunctionComment.ParamNameNoMatch
       * @param string $label_key
       *   (optional) The key to be used as a label for sorting.
       *
       * @return array[]
       *   An array of plugin definitions, sorted by category and label.
       *
       * @see https://www.drupal.org/project/drupal/issues/3354672
       *
       * @todo Uncomment the new $label_key method parameter before drupal:12.0.0.
       */
      public function getSortedDefinitions(?array $definitions = NULL /*, string $label_key = 'label' */);
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States xjm

    The current MR appears empty, so no credit is granted for @immaculatexavier.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States xjm

    A sample for the documentation page might be something like:

     /**
       * Returns sample data.
       *
       * phpcs:ignore Drupal.Commenting.FunctionComment.ParamNameNoMatch
       * @param string $added_parameter
       *   The new parameter being added.
       *
       * @return array[]
       *   The sample data.
       *
       * @see https://www.drupal.org/project/drupal/issues/3354672
       *
       * @todo Uncomment the new $added_parameter method parameter before drupal:12.0.0.
       */
      public function getSampleData(/* string $added_parameter = '' */);
    
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States xjm

    xjm โ†’ changed the visibility of the branch 3531685-ignore-specifc-sniffs to hidden.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States xjm
  • ๐Ÿ‡ณ๐Ÿ‡ฟNew Zealand quietone

    Fix link in issue summary

  • ๐Ÿ‡ณ๐Ÿ‡ฟNew Zealand quietone

    The proposal in #8 looks better. I have updated the 'how to' doc with that example as well as the issue summary. I think everything is done here.

    Setting to RTBC for a check that the doc updates are correct.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States dww

    Super nit for the sample code, not related to whatโ€™s being fixedโ€ฆ

    @return array[]
    

    Kinda weird. Probably we want either just:

    @return array
    

    Or perhaps something like:

    @return string[]
    

    or whatever. Not that we donโ€™t have functions in Drupal that return nested arrays. ๐Ÿ˜‚ but weโ€™re trying to move away from ArrayPI.

  • ๐Ÿ‡ณ๐Ÿ‡ฟNew Zealand quietone

    @dww, thanks, I did miss that last night.

    I changed it to @return string[].

Production build 0.71.5 2024