Allow phpstan inline docblocks (and other doc tags)

Created on 19 June 2023, about 1 year ago
Updated 24 June 2023, about 1 year ago

Problem/Motivation

Inline phpstan typehinting must be in done inside /** */ PHPDoc blocks.

Steps to reproduce

    /** @phpstan-var object{'cid': string, 'data': array}|false $cached */
    $cached = $this->cache->get($cid);

Proposed resolution

Exempt Drupal.Commenting.InlineComment.DocBlock when the line is a phpstan comment.

Remaining tasks

Write patch and commit.

User interface changes

API changes

Data model changes

✨ Feature request
Status

Active

Version

8.3

Component

Coder Sniffer

Created by

πŸ‡ΊπŸ‡ΈUnited States cmlara

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

Comments & Activities

  • Issue created by @cmlara
  • πŸ‡¦πŸ‡ΊAustralia dpi Perth, Australia

    @cmlara I'd recommend using normal @var blocks in Drupal code, I dont think theres a legitimate reason for our ecosystem to use @phpstan-var for inlines.

    I think I've only used them on class properties.

    My opinion its not worth the exception, however if maintainer decides otherwise I'd suggest also adding the Psalm equivalent also.

  • πŸ‡ΊπŸ‡ΈUnited States cmlara

    My opinion is it's not worth the exception, however if maintainer decides otherwise I'd suggest also adding the Psalm equivalent also.

    Realistically the Drupal sniffs should not interfere with any other external systems that have a defined standard, so I would contend that is an argument on its own to do these changes. If were going to have sniffs they need to work in all situations otherwise developers will just not use them.


    I dont think theres a legitimate reason for our ecosystem to use @phpstan-var for inlines.

    Even if they can be done with @var its always possible other software in a developers stack does not handle these enhanced types, this is part of the reason the @phpstan-* tags exist.

    Looks like our support has become a lot better in the latest release, I'm not 100% sure what version I was on a few weeks back, but phpcs was throwing a fit left and right over a number of the enriched formats so I was taking advantage of the @phpstan-* tags extensively. Looks like most (maybe all) are now handled in 8.3.20 so that I can roll back to the non phpstan specific version.

  • πŸ‡¦πŸ‡ΊAustralia dpi Perth, Australia

    Realistically the Drupal sniffs should not interfere with any other external systems that have a defined standard

    We'll I think its reasonable for the Drupal standard to reject all /**/ comments, with a single whitelisted @var. It doesnt make sense to continuously add exceptions, unless for example we allow /** @anythingUntilEndOfLine */

    Happy to continue to provide advice and anecdotes in dslack#phpstan.

  • πŸ‡¦πŸ‡ΉAustria klausi πŸ‡¦πŸ‡Ή Vienna

    I think your idea that we allow /** @anythingUntilEndOfLine */ for any doc comment tag is good. There is a trend in PHP to annotate types and variables inline in code, I think Coder can ignore that and let developers use any tag they want. I agree that @var is probably the best choice in most cases, but I'm not sure that we should enforce that as standard (at least not yet).

    Pull requests welcome to relax this check for any doc tag!

    Marking this as feature request.

Production build 0.69.0 2024