Problem/Motivation

How to typehint a service closure (w/o having to add phpdoc for all parameters)?

Steps to reproduce

- (Coming from #3221375: Wrong language field labels after `drush cr` because of Drush language negotiation, see commit)
- I'm finding a constructor without docblock
- I'm adding a service closure
- Now i have only bad choices:
-- Do not add a docblock => No IDE and phpstan bliss
-- Add docblock for ALL parameters => Clutter
-- Add docblock typehint for the service closure only => CS error

Proposed resolution

- Allow docblock-typehinting only relevant parameters
- ?

Remaining tasks

Comments

geek-merlin created an issue. See original summary.

geek-merlin’s picture

Issue summary: View changes
geek-merlin’s picture

Issue summary: View changes
geek-merlin’s picture

Issue summary: View changes
mondrake’s picture

fwiw, I started doing this in contrib

  // phpcs:disable
  /**
   * @param \Drupal\Core\Config\ConfigFactoryInterface $configFactory
   */
  // phpcs:enable
  public function __construct(
    protected readonly MimeMapManagerInterface $mimeMapManager,
    protected $configFactory,
  ) {
  }

waiting for #3419960-15: [policy, no patch] Allow docblock to be removed when modifying constructor params and #16

geek-merlin’s picture

@mondrake Thanks a lot for confirming it is an issue and a variant of phpstan-ignore is currently the only way out.

And thanks for the pointer, maybe you want to boost that by confirming my "what would make sense" over there at #3376518-190: Allow omitting @var, @param and @return tags or their descriptions if the variable name and type is enough.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.