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

Inconsistency in drupal-check #269

Open
martin-christensen opened this issue Mar 30, 2022 · 4 comments
Open

Inconsistency in drupal-check #269

martin-christensen opened this issue Mar 30, 2022 · 4 comments

Comments

@martin-christensen
Copy link

martin-christensen commented Mar 30, 2022

How is drupal-check installed?

drupal-check is installed as a dependency to my project

Environment:

  • OS: macOS
  • PHP Version: 7.4
  • Drupal core: 9.x.x

Describe the bug
Working on a private custom module and implementing drupal-check on every PR for that module.

When testing locally and in github workflows, it gives me no errors and everything seems to be fine.

Besides drupal-check, the module has dev requirements to Drupal core and requirements to contrib modules, which functionality is used/extended within this private custom module.

BUT, when including this module in an actual Drupal project and within this running drupal-check against the module, I'm getting an error,

Call to an undefined method                                      
         Drupal\Core\Entity\EntityInterface::getName().

I have also tried to follow the guide Drupal 9 Readiness, which gives the same non-error, as when running in the module directly.

Console output ran within module

Memory limit set to -1
Performing deprecation checks
Performing analysis checks
Analyzing path: /Users/mach02/projects/web/dk-news-backend/aller_aptoma
Current working directory: /Users/mach02/projects/web/dk-news-backend
Using Drupal root: /Users/mach02/projects/web/dk-news-backend/web
Using vendor root: /Users/mach02/projects/web/dk-news-backend/vendor
Assumed running as global dependency
PHPStan path: /Users/mach02/projects/web/dk-news-backend/vendor/phpstan/phpstan/phpstan.phar
PHPStan configuration path: /private/var/folders/mz/lf0jy1694vx39q03n28jtd9clydr27/T/drupal_check_phpstan_1648628179.neon
PHPStan configuration:
parameters:
        tipsOfTheDay: false
        reportUnmatchedIgnoredErrors: false
        excludePaths:
                - */tests/Drupal/Tests/Listeners/Legacy/*
                - */tests/fixtures/*.php
                - */settings*.php
                - */node_modules/*

        ignoreErrors:
                - '#\Drupal calls should be avoided in classes, use dependency injection instead#'
                - '#Plugin definitions cannot be altered.#'
                - '#Missing cache backend declaration for performance.#'
                - '#Plugin manager has cache backend specified but does not declare cache tags.#'
                - '#Unsafe usage of new static\(\)#'

        drupal:
                drupal_root: /Users/mach02/projects/web/dk-news-backend/web

        level: 4
        bootstrapFiles:
                - /Users/mach02/projects/web/dk-news-backend/vendor/mglaman/drupal-check/error-bootstrap.php

includes:
        - /Users/mach02/projects/web/dk-news-backend/vendor/phpstan/phpstan-deprecation-rules/rules.neon
        - /Users/mach02/projects/web/dk-news-backend/vendor/mglaman/phpstan-drupal/extension.neon


Executing PHPStan
Result cache not used because the metadata do not match.
 16/16 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100% < 1 sec/< 1 sec 72.5 MiB

Result cache is saved.

 [OK] No errors                                                                 

Used memory: 74.5 MB
Finished executing PHPStan
Unlinking PHPStan configuration
Return PHPStan exit code
Thanks for using drupal-check!

Consider sponsoring the development of the maintainers which make drupal-check possible:

- phpstan (ondrejmirtes): https://github.com/sponsors/ondrejmirtes
- phpstan-deprecation-rules (ondrejmirtes)): https://github.com/sponsors/ondrejmirtes
- phpstan-drupal (mglaman)): https://github.com/sponsors/mglaman
- drupal-check (mglaman)): https://github.com/sponsors/mglaman

Console output ran within a Drupal project

Memory limit set to -1
Performing deprecation checks
Performing analysis checks
Analyzing path: /Users/mach02/projects/web/dk-seoghoer-backend/web/modules/custom/dk-news-backend/aller_aptoma
Current working directory: /Users/mach02/projects/web/dk-seoghoer-backend
Using Drupal root: /Users/mach02/projects/web/dk-seoghoer-backend/web
Using vendor root: /Users/mach02/projects/web/dk-seoghoer-backend/vendor
Assumed running as global dependency
PHPStan path: /Users/mach02/projects/web/dk-seoghoer-backend/vendor/phpstan/phpstan/phpstan.phar
PHPStan configuration path: /private/var/folders/mz/lf0jy1694vx39q03n28jtd9clydr27/T/drupal_check_phpstan_1648628230.neon
PHPStan configuration:
parameters:
        tipsOfTheDay: false
        reportUnmatchedIgnoredErrors: false
        excludePaths:
                - */tests/Drupal/Tests/Listeners/Legacy/*
                - */tests/fixtures/*.php
                - */settings*.php
                - */node_modules/*

        ignoreErrors:
                - "#\\Drupal calls should be avoided in classes, use dependency injection instead#"
                - "#Plugin definitions cannot be altered.#"
                - "#Missing cache backend declaration for performance.#"
                - "#Plugin manager has cache backend specified but does not declare cache tags.#"
                - "#Unsafe usage of new static\\(\\)#"

        drupal:
                drupal_root: /Users/mach02/projects/web/dk-seoghoer-backend/web

        level: 4
        bootstrapFiles:
                - /Users/mach02/projects/web/dk-seoghoer-backend/vendor/mglaman/drupal-check/error-bootstrap.php

includes:
        - /Users/mach02/projects/web/dk-seoghoer-backend/vendor/phpstan/phpstan-deprecation-rules/rules.neon
        - /Users/mach02/projects/web/dk-seoghoer-backend/vendor/mglaman/phpstan-drupal/extension.neon


Executing PHPStan
Result cache not used because the metadata do not match.
 16/16 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100% 4 secs/4 secs 124.5 MiB

Result cache is saved.
 ------ ---------------------------------------------------- 
  Line   src/Plugin/rest/resource/AllerAptomaApiContent.php  
 ------ ---------------------------------------------------- 
  272    Call to an undefined method                         
         Drupal\Core\Entity\EntityInterface::getName().      
 ------ ---------------------------------------------------- 


 [ERROR] Found 1 error                                                          

Used memory: 132.5 MB
Finished executing PHPStan
Unlinking PHPStan configuration
Return PHPStan exit code
Thanks for using drupal-check!

Consider sponsoring the development of the maintainers which make drupal-check possible:

- phpstan (ondrejmirtes): https://github.com/sponsors/ondrejmirtes
- phpstan-deprecation-rules (ondrejmirtes)): https://github.com/sponsors/ondrejmirtes
- phpstan-drupal (mglaman)): https://github.com/sponsors/mglaman
- drupal-check (mglaman)): https://github.com/sponsors/mglaman
@martin-christensen
Copy link
Author

@mglaman any suggestions to the above? 🤞🏼

@mglaman
Copy link
Owner

mglaman commented Mar 31, 2022

This isn't inconsistent. Does that method exist in that interface or a different one?

You're running with analysis and deprecations

Performing deprecation checks
Performing analysis checks

See https://www.drupal.org/docs/develop/development-tools/phpstan/fixing-reports-of-undefined-methods

@martin-christensen
Copy link
Author

Thanks for your reply!

Yes, I know and also get how to fix this.

My actual question is, why it only gives me this error when running drupal-check on our custom Drupal project, where the custom module is required.

The error is about a Core thing, so I should give the same error when following the guide from the wiki, which states to get a clean Drupal Core, require the custom module and running drupal-check. But in that case, it gives me no errors, which is weird.

@mglaman
Copy link
Owner

mglaman commented Apr 1, 2022

So when running the custom module outside of your normal project it doesn't error? The file being src/Plugin/rest/resource/AllerAptomaApiContent.php in aller_aptoma

See the one without error:

Analyzing path: /Users/mach02/projects/web/dk-news-backend/aller_aptoma	
Current working directory: /Users/mach02/projects/web/dk-news-backend	
Using Drupal root: /Users/mach02/projects/web/dk-news-backend/web	
Using vendor root: /Users/mach02/projects/web/dk-news-backend/vendor

And with:

Analyzing path: /Users/mach02/projects/web/dk-seoghoer-backend/web/modules/custom/dk-news-backend/aller_aptoma
Current working directory: /Users/mach02/projects/web/dk-seoghoer-backend
Using Drupal root: /Users/mach02/projects/web/dk-seoghoer-backend/web
Using vendor root: /Users/mach02/projects/web/dk-seoghoer-backend/vendor

The one with an error has your code properly placed in Drupal for analysis.

Right now it's not possible to analyze a module outside of where Drupal would expect to find extensions

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