Problem/Motivation

Fix

i$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\Core\\\\Entity\\\\ContentEntityBase\\:\\:getTranslatedField\\(\\) return type with generic interface Drupal\\\\Core\\\\Field\\\\FieldItemListInterface does not specify its types\\: T$#',
	'identifier' => 'missingType.generics',
	'count' => 1,
	'path' => __DIR__ . '/lib/Drupal/Core/Entity/ContentEntityBase.php',
];

and similar.

Steps to reproduce

grep "FieldItemListInterface does not specify its types" -B1 -A4 core/.phpstan-baseline.php

Proposed resolution

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Issue fork drupal-3496417

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

mondrake created an issue. See original summary.

mondrake’s picture

mondrake’s picture

phpstan-drupal has a stub that defines FieldItemListInterface as a generic, so we need to pass the type in the PHPDocs here.

See https://github.com/mglaman/phpstan-drupal/blob/main/stubs/Drupal/Core/Fi...

mondrake’s picture

Status: Active » Needs review
mondrake’s picture

TBH I think it’s nonsense to have core lacking appropriate PHPDoc, for drupal-phpstan to write a stub gapfill, and then that gapfill to force back core implementations’ PHPDocs to be adjusted…

I would suggest to move the definitions in the stub from drupal-php to core as part of this issue.

mglaman’s picture

phpstan-drupal uses a stub provider, so we can fix here and back port anything to phpstan-drupal and use a version check on Drupal to decide if the phpstan-drupal stub should be loaded or not

mondrake’s picture

Done #7 for the Drupal core part (I think).

smustgrave’s picture

Left a comment on the MR but leaving in review for someone more familiar

smustgrave’s picture

Status: Needs review » Needs work

Thanks for the response @mglaman. Moving to NW for rebase.

If you are another contributor eager to jump in, please allow the original poster @mglaman or @mondrake at least 48 hours to respond to feedback first, so they have the opportunity to finish what they started!

mondrake’s picture

Status: Needs work » Needs review

Rebased, only merge conflicts resolved.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Rebase seems good.

nod_’s picture

Status: Reviewed & tested by the community » Needs work

merge conflict

mondrake’s picture

Status: Needs work » Reviewed & tested by the community

merged with 11.x, no conflicts. Dunno why GitLab still reports a merge error.

catch’s picture

Status: Reviewed & tested by the community » Needs review

I'm really not sure about using templates like this. I realise I'm in the minority using vim (and without whatever vim support would take advantage of this, there's probably something somewhere), but don't think I'm the only one. There's also reading docs on api.drupal.org or gitlab which people sometimes do.

smustgrave’s picture

Status: Needs review » Needs work

appears to need a rebase

If you are another contributor eager to jump in, please allow the previous poster at least 48 hours to respond to feedback first, so they have the opportunity to finish what they started!

mondrake’s picture

The weirdness here is that this MR is practically just a c/p of (some of) the stubs that are defined in mglaman/phpstan-drupal. The difference is the use of FQCN as per Drupal code standards vs class names and use imports.

If we don't do this, Drupal core is not compatible with its own PHPStan tooling. Therefore we should remove the stubs from mglaman/phpstan-drupal if we aim at clearing the baseline... fun.

mondrake’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Needs work

Appears some feedback was added to the MR.

gselderslaghs’s picture

#9 works as expected, @mglaman thanks for saving me a headache on this one

mondrake’s picture

Status: Needs work » Needs review

Rebased and addressed feedback.

mstrelan’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

Added steps to reproduce, can confirm all 9 instances in the baseline are fixed in this MR.

I'm really not sure about using templates like this. I realise I'm in the minority using vim (and without whatever vim support would take advantage of this, there's probably something somewhere), but don't think I'm the only one. There's also reading docs on api.drupal.org or gitlab which people sometimes do.

I'm guessing this is specifically about ListInterface, which is the only class that uses the templates outside of where they are defined. This concern is understandable in that looking at that method in isolation doesn't tell you what T is. I think longwaves suggestion in #15 to use @phpstan-return and leaving the original @return for these addresses that concern, so I think we can make this RTBC. Please set back if you're not satisfied with that.

We could of course have a coding standards discussion for use of templates, e.g. use @phpstan- params when referring to templates, but I don't think we should block this on that issue.

longwave’s picture

Version: 11.x-dev » 11.3.x-dev
Status: Reviewed & tested by the community » Fixed

Been sitting on this one a while but given we agree that PHPStan helps more than it hinders, I think this is the only way forward. @mglaman's phpstan-drupal has already implemented this and fields are such a key part of Drupal that improving static analysis here will help more people. I think that @catch's concerns are resolved by keeping @return for humans and using @phpstan-return for machines to read.

Committed and pushed 41ee2804c3f to 11.x and 567f20edeaa to 11.3.x. Thanks!

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

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

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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