Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drupal Check incorrectly reporting "missing methods" on Interfaces, when methods actually exist on implementing class. #253

Closed
lhridley opened this issue Dec 24, 2021 · 6 comments

Comments

@lhridley
Copy link

lhridley commented Dec 24, 2021

How is drupal-check installed?

drupal-check is installed globally via Composer

Environment:

  • OS: Linux
  • PHP Version: 8.0
  • Drupal core: 10.x.x (aliased as 9.3)

Describe the bug
Expected Behavior -- no detected errors

Actual Behavior -- errors flagged for "undefined method" on Interface.

The classes in question actually extends a Drupal Class that implements Drupal\Core\Entity\EntityInterface, but the declaration of the methods are not required on the Interface itself. So, it appears that the scanner is incorrectly flagging this as an "undefined method" on the Interface, even though the method is defined for the module's class in questions.

Console output

Link to public project Github Actions output:

@mglaman
Copy link
Owner

mglaman commented Jan 1, 2022

You need to type hint your code, then.

@mglaman mglaman closed this as completed Jan 1, 2022
@lhridley
Copy link
Author

lhridley commented Jan 2, 2022

Thank @mglaman !

@mglaman
Copy link
Owner

mglaman commented Jan 2, 2022

@lhridley sorry for the quick reply earlier, so use /** @var */ or my favorite instanceof in if or assert.

Should I add documentation about this in this project, phpstan-drupal, or even Drupal.org?

@lhridley
Copy link
Author

lhridley commented Jan 2, 2022

Hey @mglaman -- your comment is sufficient to point me in the right direction, but the error thrown is a bit cryptic.

A more helpful and informative message would be extremely useful thought.

If the message can't be made more informative somehow, then some documentation would be most helpful.

@mglaman
Copy link
Owner

mglaman commented Jan 2, 2022

The message can't really be improved. And we can't easily enhance it. So documentation on how to write more "aware" code vis type hinting is needed.

@mglaman
Copy link
Owner

mglaman commented Jan 3, 2022

I've started here: https://www.drupal.org/docs/develop/development-tools/phpstan

I'll add a page about non-existent methods and type hinting later today

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants