Problem/Motivation

Amongst the current suppressions found in the PHPStan level 1 baseline are: Call to method getDefinitions() on an unknown class Drupal\Core\Plugin\CategorizingPluginManagerTrait. and Call to method getSortedDefinitions() on an unknown class Drupal\Core\Plugin\CategorizingPluginManagerTrait..

This issue exists to fix all of those.

Steps to reproduce

- Run PHPStan on level 1 and see the above issue amongst all others.

Proposed resolution

- Solve all of the reported issues for the above mentioned.
- Run PHPStan on level 1 and don't see the above issue any more.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Issue fork drupal-3352916

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

Spokje created an issue. See original summary.

spokje’s picture

Status: Active » Needs work

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

spokje’s picture

Status: Needs work » Needs review
mondrake’s picture

Status: Needs review » Needs work

Left a comment in the MR. Can you help me understand @Spokje?

spokje’s picture

Status: Needs work » Needs review

@mondrake: Tried a (weak) explanation in the MR thread.

mondrake’s picture

Comment in MR, thanks!

spokje’s picture

@mondrake Makes sense, will change it shortly.

If it turns out to be too much we can always revert to the "minimal" working cas at https://git.drupalcode.org/project/drupal/-/merge_requests/3794/diffs?co...

spokje’s picture

Assigned: Unassigned » spokje
Status: Needs review » Needs work
mondrake’s picture

BTW: is the issue title still accurate?

spokje’s picture

Title: Fix PHPStan L1 errors "Call to method foo() on an unknown class Bar\Baz." » Fix PHPStan L1 errors "Call to method getDefinitions() on an unknown class Drupal\Core\Plugin\CategorizingPluginManagerTrait."
Issue summary: View changes

BTW: is the issue title still accurate?

You're right, we can be more specific here.

spokje’s picture

Title: Fix PHPStan L1 errors "Call to method getDefinitions() on an unknown class Drupal\Core\Plugin\CategorizingPluginManagerTrait." » Fix PHPStan L1 errors "Call to method getDefinitions()/getSortedDefinitions() on an unknown class Drupal\Core\Plugin\CategorizingPluginManagerTrait."
Issue summary: View changes
spokje’s picture

Assigned: spokje » Unassigned
Status: Needs work » Needs review

Ok, let's give this a new NR round :)

mondrake’s picture

Status: Needs review » Reviewed & tested by the community

To me, this is the cleanest way to fix this mess…

longwave’s picture

Status: Reviewed & tested by the community » Needs work

Adding an argument to the interface is not backward compatible with any existing implementations, and there are a handful in contrib at least:

http://grep.xnddx.ru/search?text=getSortedDefinitions&filename=

mondrake’s picture

I have opened #3354524: Document how to add additional parameters to interface methods to discuss how to manage cases where interfaces are wrong and we cannot change them

spokje’s picture

Title: Fix PHPStan L1 errors "Call to method getDefinitions()/getSortedDefinitions() on an unknown class Drupal\Core\Plugin\CategorizingPluginManagerTrait." » [PP-1] Fix PHPStan L1 errors "Call to method getDefinitions()/getSortedDefinitions() on an unknown class Drupal\Core\Plugin\CategorizingPluginManagerTrait."
Status: Needs work » Postponed

And another PHPStan issue grinds to a halt, postponing on #3354524: Document how to add additional parameters to interface methods

mondrake’s picture

Looking for #3236391: (outdated) Replace func_get_args with variable-length argument in FormBuilder to go in, that sets a reference for prepping the addition of arguments to interface methods, and this could follow.

mondrake’s picture

mondrake’s picture

Typehinting of return type follows the covariance rules https://www.php.net/manual/en/language.oop5.variance.php, so adding one to the interface means BC break because implementing classes must at least implement the same return type.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

bbrala’s picture

Title: [PP-1] Fix PHPStan L1 errors "Call to method getDefinitions()/getSortedDefinitions() on an unknown class Drupal\Core\Plugin\CategorizingPluginManagerTrait." » Fix PHPStan L1 errors "Call to method getDefinitions()/getSortedDefinitions() on an unknown class Drupal\Core\Plugin\CategorizingPluginManagerTrait."
Status: Postponed » Needs work

How to change signatures in interfaces has been documented: #3354524: Document how to add additional parameters to interface methods

longwave’s picture

Status: Needs work » Needs review

Traits can have abstract methods, if we do that we can remove the @var and it seems happy enough? See MR!10468.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs Review Queue Initiative

Nice! I was not aware of the abstract methods approach but will be remembering it. Change appears pretty straight forward and addresses the task. LGTM

larowlan’s picture

Status: Reviewed & tested by the community » Fixed

Committed to 11.x thanks!

  • larowlan committed bf6900b7 on 11.x
    Issue #3352916 by spokje, mondrake, longwave, vladimiraus: Fix PHPStan...

Status: Fixed » Closed (fixed)

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