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

Issue fork coder-3367776

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

cmlara created an issue. See original summary.

dpi’s picture

@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.

PHPStan/Psalm advanced types work in @var inlines perfectly fine, as far as I'm aware.

I think I've only used phpstan-var on class properties.

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

cmlara’s picture

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.

dpi’s picture

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.

klausi’s picture

Title: False Postive on phpstan inline docblocks » Allow phpstan inline docblocks (and other doc tags)
Version: 8.3.20 » 8.3.x-dev
Category: Bug report » Feature request

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.

twiesing made their first commit to this issue’s fork.

twiesing’s picture

I've created a merge request to relax the check based on the above.
In the MR I decided to allow doc comments that start with a doc tag (preceding whitespace is fine).

To illustrate, I've also added a couple of test cases:

function test3() {
  /** I am not allowed. */
  something();

  /**
    * I am also not allowed.
    * Even though I go on multiple lines.
    */
  something();

  /** @some-unknown-tag I am allowed. */
  something();

  /**
   *
   * @some-tag-on-the-third-line */
  something();

  /**
   * @some-tag-here
   *
   * Additonal text after is fine.
   */
  something();

  /**
   * There is some text here before the doc tag.
   *
   * This should not be allowed.
   *
   * @some-other-tag
   */
  something();
}
klausi’s picture

Status: Active » Needs work

Thanks! Can you open a PR at https://github.com/pfrenssen/coder/pulls ? We are still doing the pull requests there for now.

twiesing’s picture

Done: https://github.com/pfrenssen/coder/pull/269

Should I close the MR on GitLab?

twiesing’s picture

Is there any estimate on how long it takes from a GitHub PR until the code appears in a release?

  • twiesing authored d7b53128 on 8.3.x
    fix(InlineComment): Allow custom docblock tags (#3367776)
    
    Previously,...
klausi’s picture

Status: Needs work » Fixed

Thanks, merged!

Usually I try to make releases every 3 months if changes were merged in that period.

I think I can make a new release at Drupalcon on contribution day next Friday.

Now that this issue is closed, please review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, please credit people who helped resolve this issue.

klausi’s picture

Coder 8.3.31 released with this fix!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.