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

Error: Class was not found while trying to analyse it - autoloading is probably not configured properly. #55

Closed
vijaycs85 opened this issue Apr 27, 2019 · 16 comments
Labels
needs more information Further information is requested

Comments

@vijaycs85
Copy link
Contributor

Problem

drupal-checker modules/contrib/[module name] throws Class [Class name] was not found while trying to analyse it - autoloading is probably not configured properly.

Environment details

  • drupal-chcker (v 1.0.8) installed globally (composer global require mglaman/drupal-checker)
  • Drupal installation with core 8.7.x
  • Contrib module installed via composer (composer require --prefer-source drupal/cloudflare)
  • Module is enabled and functional.

Output

  drupal8 git:(8.7.x) ✗ drupal-check modules/contrib/cloudflare
 ------ -------------------------------------------------------------------------------------------------------------------------------------------------------------------
  Line   modules/cloudflarepurger/src/EventSubscriber/CloudFlareCacheTagHeaderGenerator.php
 ------ -------------------------------------------------------------------------------------------------------------------------------------------------------------------
         Class Drupal\cloudflarepurger\EventSubscriber\CloudFlareCacheTagHeaderGenerator was not found while trying to analyse it - autoloading is probably not configured
         properly.
 ------ -------------------------------------------------------------------------------------------------------------------------------------------------------------------

 ------ ----------------------------------------------------------------------------------------------------------------------------------------------------------------
  Line   modules/cloudflarepurger/src/Plugin/Purge/DiagnosticCheck/ApiRateLimitCheck.php
 ------ ----------------------------------------------------------------------------------------------------------------------------------------------------------------
         Class Drupal\cloudflarepurger\Plugin\Purge\DiagnosticCheck\ApiRateLimitCheck was not found while trying to analyse it - autoloading is probably not configured
         properly.
 ------ ----------------------------------------------------------------------------------------------------------------------------------------------------------------

 ------ -------------------------------------------------------------------------------------------------------------------------------------------------------------
  Line   modules/cloudflarepurger/src/Plugin/Purge/DiagnosticCheck/ComposerDependenciesCheck.php
 ------ -------------------------------------------------------------------------------------------------------------------------------------------------------------
         Class Drupal\cloudflarepurger\Plugin\Purge\DiagnosticCheck\ComposerDependenciesCheck was not found while trying to analyse it - autoloading is probably not
         configured properly.
 ------ -------------------------------------------------------------------------------------------------------------------------------------------------------------

 ------ --------------------------------------------------------------------------------------------------------------------------------------------------------------
  Line   modules/cloudflarepurger/src/Plugin/Purge/DiagnosticCheck/CredentialCheck.php
 ------ --------------------------------------------------------------------------------------------------------------------------------------------------------------
         Class Drupal\cloudflarepurger\Plugin\Purge\DiagnosticCheck\CredentialCheck was not found while trying to analyse it - autoloading is probably not configured
         properly.
 ------ --------------------------------------------------------------------------------------------------------------------------------------------------------------

 ------ ----------------------------------------------------------------------------------------------------------------------------------------------------------------------
  Line   modules/cloudflarepurger/src/Plugin/Purge/DiagnosticCheck/DailyTagPurgeLimitCheck.php
 ------ ----------------------------------------------------------------------------------------------------------------------------------------------------------------------
         Class Drupal\cloudflarepurger\Plugin\Purge\DiagnosticCheck\DailyTagPurgeLimitCheck was not found while trying to analyse it - autoloading is probably not configured
         properly.
 ------ ----------------------------------------------------------------------------------------------------------------------------------------------------------------------
@mglaman
Copy link
Owner

mglaman commented Apr 28, 2019

It looks like I should expand #54 to not only test the built phar but also include it globally and test. And test with Cloudflare.

@johnzzon
Copy link

Seeing this issue as well.

Installed via: $ composer global require mglaman/drupal-check
Version: Drupal Check 1.0.8
Completely new project via: $ composer create-project drupal-composer/drupal-project:8.x-dev check --no-interaction --stability=dev
Install a contrib module: $ composer require drupal/coffee
Run drupal-check: $ drupal-check -vvv web/modules/contrib/coffee
Output:

Current working directory: /some-place/check
Using Drupal root: /some-place/check/web
Using vendor root: /some-place/check/vendor
Using autoloader: /some-place/check/vendor/autoload.php
/some-place/check/web/modules/contrib/coffee/tests/src/Functional/CoffeeTest.php
/some-place/check/web/modules/contrib/coffee/tests/src/Kernel/CoffeeCommandsTest.php
/some-place/check/web/modules/contrib/coffee/coffee.api.php
/some-place/check/web/modules/contrib/coffee/src/Form/CoffeeConfigurationForm.php
/some-place/check/web/modules/contrib/coffee/src/Controller/CoffeeController.php
 ------ ---------------------------------------------------------------------------------------------------------------------------------------------
  Line   src/Controller/CoffeeController.php
 ------ ---------------------------------------------------------------------------------------------------------------------------------------------
         Class Drupal\coffee\Controller\CoffeeController was not found while trying to analyse it - autoloading is probably not configured properly.
 ------ ---------------------------------------------------------------------------------------------------------------------------------------------

 ------ ----------------------------------------------------------------------------------------------------------------------------------------------
  Line   src/Form/CoffeeConfigurationForm.php
 ------ ----------------------------------------------------------------------------------------------------------------------------------------------
         Class Drupal\coffee\Form\CoffeeConfigurationForm was not found while trying to analyse it - autoloading is probably not configured properly.
 ------ ----------------------------------------------------------------------------------------------------------------------------------------------

@mglaman
Copy link
Owner

mglaman commented Apr 29, 2019

Interesting. I'll add checks on #54

mglaman added a commit that referenced this issue May 3, 2019
@mglaman mglaman added the autoloading Problems with autoloading label May 3, 2019
@mglaman
Copy link
Owner

mglaman commented May 3, 2019

@vijaycs85 those failures are actually due to purge not being available. Cloudflare should add purge as its require-dev. It's just masked.

mglaman added a commit that referenced this issue May 3, 2019
mglaman added a commit that referenced this issue May 3, 2019
@mglaman
Copy link
Owner

mglaman commented May 3, 2019

@johnzzon I also cannot reproduce.

I just tagged 1.0.9, care to try that? Also, my tests are using the phar. I'll make an update attempting via the global install.

@mglaman
Copy link
Owner

mglaman commented May 3, 2019

@mglaman mglaman added needs more information Further information is requested and removed autoloading Problems with autoloading labels May 3, 2019
@dalin-
Copy link

dalin- commented May 4, 2019

Still no go.

$ cgr update mglaman/drupal-check
# ...
  - Updating mglaman/phpstan-drupal (0.11.5 => 0.11.6): Loading from cache
  - Updating mglaman/drupal-check (1.0.8 => 1.0.9): Loading from cache
# ...
$ cd path/to/composer/drupal-8/project
$ drupal-check web/modules/custom
 ------ -----------------------------------------------------------------------------------------------------------------------------------------------------------
  Line   csps_blocks/src/Controller/CSPSBlocksAlertController.php
 ------ -----------------------------------------------------------------------------------------------------------------------------------------------------------
         Class Drupal\csps_blocks\Controller\CSPSBlocksAlertController was not found while trying to analyse it - autoloading is probably not configured properly.
 ------ -----------------------------------------------------------------------------------------------------------------------------------------------------------
# etc.
# ...
[ERROR] Found 23 errors

@mglaman
Copy link
Owner

mglaman commented May 5, 2019

@dalin- what is cgr? Can you try without cgr and using the phar? I have automated test coverage for the Phar and composer global require.

Is this cgr? https://github.com/consolidation/cgr? If so, I'd appreicate if you tested the phar. If that doesn't work, there is more to be done. If it does, then we need to open an issue specifically for CGR.

Can you also run with -vvv for debug output and post here?

@dalin-
Copy link

dalin- commented May 6, 2019

@mglaman
Huh. That's weird. Usually CGR solves all sorts of problems. I've never seen it create any. But yes, the .phar worked.

FWIW, those first 4 lines are identical whether I'm using CGR, or the .phar.

What's weird is that when I run via CGR it's only looking at class files and not at .module/.install/etc. files.

Current working directory: /Users/dave/Sites/columbia-sps
Using Drupal root: /Users/dave/Sites/columbia-sps/web
Using vendor root: /Users/dave/Sites/columbia-sps/vendor
Using autoloader: /Users/dave/Sites/columbia-sps/vendor/autoload.php
/Users/dave/Sites/columbia-sps/web/modules/custom/csps_clunify/src/Plugin/Field/FieldFormatter/CSPSClunifyFieldFormatter.php
/Users/dave/Sites/columbia-sps/web/modules/custom/csps_formatters/src/Plugin/Field/FieldFormatter/CSPSLinkFormatter.php
/Users/dave/Sites/columbia-sps/web/modules/custom/csps_formatters/src/Plugin/Field/FieldFormatter/LinkStaticFormatter.php
/Users/dave/Sites/columbia-sps/web/modules/custom/csps_formatters/src/Plugin/Field/FieldFormatter/CspsFormattersDateFormatter.php
/Users/dave/Sites/columbia-sps/web/modules/custom/csps_formatters/src/Plugin/Field/FieldFormatter/CSPSEntityReferenceLabelFormatter.php
/Users/dave/Sites/columbia-sps/web/modules/custom/csps_formatters/src/Plugin/Field/FieldFormatter/CspsTextFormatter.php
/Users/dave/Sites/columbia-sps/web/modules/custom/csps_video/src/Plugin/Field/FieldFormatter/VideoWithApi.php
/Users/dave/Sites/columbia-sps/web/modules/custom/csps_updates/src/Controller/CSPSMainConfig.php
/Users/dave/Sites/columbia-sps/web/modules/custom/csps_twitter/src/Form/TwitterConfigurationForm.php
/Users/dave/Sites/columbia-sps/web/modules/custom/csps_twitter/src/Plugin/Field/FieldFormatter/TwitterFormatter.php
/Users/dave/Sites/columbia-sps/web/modules/custom/csps_search/src/Plugin/facets/processor/CSPSDisplayFacetProcessor.php
/Users/dave/Sites/columbia-sps/web/modules/custom/csps_migrate/src/Plugin/migrate/source/CSPSArticleToMediaMention.php
/Users/dave/Sites/columbia-sps/web/modules/custom/csps_migrate/src/Plugin/migrate/source/CSPSNewsArticleToArticle.php
/Users/dave/Sites/columbia-sps/web/modules/custom/csps_migrate/src/Plugin/migrate/process/Paragraph.php
/Users/dave/Sites/columbia-sps/web/modules/custom/csps_migrate/src/Plugin/migrate/process/ClunifyFix.php
/Users/dave/Sites/columbia-sps/web/modules/custom/csps_migrate/src/Plugin/migrate/process/ParagraphProcessBase.php
/Users/dave/Sites/columbia-sps/web/modules/custom/csps_blocks/src/Plugin/Block/CSPSBlocksAlert.php
/Users/dave/Sites/columbia-sps/web/modules/custom/csps_blocks/src/Controller/CSPSBlocksAlertThemeController.php
/Users/dave/Sites/columbia-sps/web/modules/custom/csps_blocks/src/Controller/CSPSBlocksAlertController.php
 ------ -----------------------------------------------------------------------------------------------------------------------------------------------------------
  Line   csps_blocks/src/Controller/CSPSBlocksAlertController.php
 ------ -----------------------------------------------------------------------------------------------------------------------------------------------------------
         Class Drupal\csps_blocks\Controller\CSPSBlocksAlertController was not found while trying to analyse it - autoloading is probably not configured properly.
 ------ -----------------------------------------------------------------------------------------------------------------------------------------------------------

 ------ ----------------------------------------------------------------------------------------------------------------------------------------------------------------
  Line   csps_blocks/src/Controller/CSPSBlocksAlertThemeController.php
 ------ ----------------------------------------------------------------------------------------------------------------------------------------------------------------
         Class Drupal\csps_blocks\Controller\CSPSBlocksAlertThemeController was not found while trying to analyse it - autoloading is probably not configured properly.
 ------ ----------------------------------------------------------------------------------------------------------------------------------------------------------------

 ------ ---------------------------------------------------------------------------------------------------------------------------------------------------
  Line   csps_blocks/src/Plugin/Block/CSPSBlocksAlert.php
 ------ ---------------------------------------------------------------------------------------------------------------------------------------------------
         Class Drupal\csps_blocks\Plugin\Block\CSPSBlocksAlert was not found while trying to analyse it - autoloading is probably not configured properly.
 ------ ---------------------------------------------------------------------------------------------------------------------------------------------------

 ------ -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  Line   csps_clunify/src/Plugin/Field/FieldFormatter/CSPSClunifyFieldFormatter.php
 ------ -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
         Class Drupal\csps_clunify\Plugin\Field\FieldFormatter\CSPSClunifyFieldFormatter was not found while trying to analyse it - autoloading is probably not configured properly.
 ------ -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------

 ------ ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  Line   csps_formatters/src/Plugin/Field/FieldFormatter/CSPSEntityReferenceLabelFormatter.php
 ------ ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
         Class Drupal\csps_formatters\Plugin\Field\FieldFormatter\CSPSEntityReferenceLabelFormatter was not found while trying to analyse it - autoloading is probably not configured properly.
 ------ ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

 ------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  Line   csps_formatters/src/Plugin/Field/FieldFormatter/CSPSLinkFormatter.php
 ------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------
         Class Drupal\csps_formatters\Plugin\Field\FieldFormatter\CSPSLinkFormatter was not found while trying to analyse it - autoloading is probably not configured properly.
 ------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------

 ------ ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  Line   csps_formatters/src/Plugin/Field/FieldFormatter/CspsFormattersDateFormatter.php
 ------ ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
         Class Drupal\csps_formatters\Plugin\Field\FieldFormatter\CspsFormattersDateFormatter was not found while trying to analyse it - autoloading is probably not configured properly.
 ------ ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

 ------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  Line   csps_formatters/src/Plugin/Field/FieldFormatter/CspsTextFormatter.php
 ------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------
         Class Drupal\csps_formatters\Plugin\Field\FieldFormatter\CspsTextFormatter was not found while trying to analyse it - autoloading is probably not configured properly.
 ------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------

 ------ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  Line   csps_formatters/src/Plugin/Field/FieldFormatter/LinkStaticFormatter.php
 ------ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------
         Class Drupal\csps_formatters\Plugin\Field\FieldFormatter\LinkStaticFormatter was not found while trying to analyse it - autoloading is probably not configured properly.
 ------ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------

 ------ ---------------------------------------------------------------------------------------------------------------------------------------------------------
  Line   csps_migrate/src/Plugin/migrate/process/ClunifyFix.php
 ------ ---------------------------------------------------------------------------------------------------------------------------------------------------------
         Class Drupal\csps_migrate\Plugin\migrate\process\ClunifyFix was not found while trying to analyse it - autoloading is probably not configured properly.
 ------ ---------------------------------------------------------------------------------------------------------------------------------------------------------

 ------ --------------------------------------------------------------------------------------------------------------------------------------------------------
  Line   csps_migrate/src/Plugin/migrate/process/Paragraph.php
 ------ --------------------------------------------------------------------------------------------------------------------------------------------------------
         Class Drupal\csps_migrate\Plugin\migrate\process\Paragraph was not found while trying to analyse it - autoloading is probably not configured properly.
 ------ --------------------------------------------------------------------------------------------------------------------------------------------------------

 ------ -------------------------------------------------------------------------------------------------------------------------------------------------------------------
  Line   csps_migrate/src/Plugin/migrate/process/ParagraphProcessBase.php
 ------ -------------------------------------------------------------------------------------------------------------------------------------------------------------------
         Class Drupal\csps_migrate\Plugin\migrate\process\ParagraphProcessBase was not found while trying to analyse it - autoloading is probably not configured properly.
 ------ -------------------------------------------------------------------------------------------------------------------------------------------------------------------

 ------ -----------------------------------------------------------------------------------------------------------------------------------------------------------------------
  Line   csps_migrate/src/Plugin/migrate/source/CSPSArticleToMediaMention.php
 ------ -----------------------------------------------------------------------------------------------------------------------------------------------------------------------
         Class Drupal\csps_migrate\Plugin\migrate\source\CSPSArticleToMediaMention was not found while trying to analyse it - autoloading is probably not configured properly.
 ------ -----------------------------------------------------------------------------------------------------------------------------------------------------------------------

 ------ ----------------------------------------------------------------------------------------------------------------------------------------------------------------------
  Line   csps_migrate/src/Plugin/migrate/source/CSPSNewsArticleToArticle.php
 ------ ----------------------------------------------------------------------------------------------------------------------------------------------------------------------
         Class Drupal\csps_migrate\Plugin\migrate\source\CSPSNewsArticleToArticle was not found while trying to analyse it - autoloading is probably not configured properly.
 ------ ----------------------------------------------------------------------------------------------------------------------------------------------------------------------

 ------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  Line   csps_search/src/Plugin/facets/processor/CSPSDisplayFacetProcessor.php
 ------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------
         Class Drupal\csps_search\Plugin\facets\processor\CSPSDisplayFacetProcessor was not found while trying to analyse it - autoloading is probably not configured properly.
 ------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------

 ------ -----------------------------------------------------------------------------------------------------------------------------------------------------
  Line   csps_twitter/src/Form/TwitterConfigurationForm.php
 ------ -----------------------------------------------------------------------------------------------------------------------------------------------------
         Class Drupal\csps_twitter\Form\TwitterConfigurationForm was not found while trying to analyse it - autoloading is probably not configured properly.
 ------ -----------------------------------------------------------------------------------------------------------------------------------------------------

 ------ --------------------------------------------------------------------------------------------------------------------------------------------------------------------
  Line   csps_twitter/src/Plugin/Field/FieldFormatter/TwitterFormatter.php
 ------ --------------------------------------------------------------------------------------------------------------------------------------------------------------------
         Class Drupal\csps_twitter\Plugin\Field\FieldFormatter\TwitterFormatter was not found while trying to analyse it - autoloading is probably not configured properly.
 ------ --------------------------------------------------------------------------------------------------------------------------------------------------------------------

 ------ -------------------------------------------------------------------------------------------------------------------------------------------------
  Line   csps_updates/src/Controller/CSPSMainConfig.php
 ------ -------------------------------------------------------------------------------------------------------------------------------------------------
         Class Drupal\csps_updates\Controller\CSPSMainConfig was not found while trying to analyse it - autoloading is probably not configured properly.
 ------ -------------------------------------------------------------------------------------------------------------------------------------------------

 ------ --------------------------------------------------------------------------------------------------------------------------------------------------------------
  Line   csps_video/src/Plugin/Field/FieldFormatter/VideoWithApi.php
 ------ --------------------------------------------------------------------------------------------------------------------------------------------------------------
         Class Drupal\csps_video\Plugin\Field\FieldFormatter\VideoWithApi was not found while trying to analyse it - autoloading is probably not configured properly.
 ------ --------------------------------------------------------------------------------------------------------------------------------------------------------------

 ----------------------------------------------------------------
  Error
 ----------------------------------------------------------------
  Ignored error pattern #\Drupal calls should be avoided in
  classes, use dependency injection instead# was not matched in
  reported errors.
  Ignored error pattern #Plugin definitions cannot be altered.#
  was not matched in reported errors.
  Ignored error pattern #Missing cache backend declaration for
  performance.# was not matched in reported errors.
  Ignored error pattern #Plugin manager has cache backend
  specified but does not declare cache tags.# was not matched in
  reported errors.
 ----------------------------------------------------------------


 [ERROR] Found 23 errors

@mglaman
Copy link
Owner

mglaman commented May 6, 2019

Huh. That's weird. Usually CGR solves all sorts of problems. I've never seen it create any. But yes, the .phar worked.

CGR resolves dependency problems but creates a whole new mess for assumptions. And Drupal Check relies on a lot of assumptions. Would you mind opening a new issue specifically for CGR installs? I can then whip up a CircleCI job and figure out what is happening

@rpsu
Copy link

rpsu commented May 6, 2019

version 1.0.9 fixes the same issue also when running checks locally, when using drupal-project-template (https://github.com/mglaman/drupal-check#usage)

autoloading is probably not configured properly

@dalin-
Copy link

dalin- commented May 6, 2019

Opened an issue with CGR:
consolidation/cgr#37

@mglaman
Copy link
Owner

mglaman commented May 6, 2019

@dalin- oh sorry I meant here, I probably need to do some extra work on my end.

@mglaman
Copy link
Owner

mglaman commented May 6, 2019

I'm going to close this as I think the original issue is fixed, and then tackle CGR.

@mglaman mglaman closed this as completed May 6, 2019
@mikemadison13
Copy link

I'm running into this issue while trying to scan my custom modules. Contrib seem to be ok. The use case I am trying to support is:

  1. add mglaman/drupal-check to a project level composer (although, also happening globally)
  2. run drupal-check against docroot/modules/custom to check for deprecated code
  3. automate this process in CI so that deprecation checks are run with other validation and testing frameworks.

Every custom module in my codebase throws the <class> was not found while trying to analyse it - autoloading is probably not configured properly.

@mglaman
Copy link
Owner

mglaman commented May 7, 2019

@mikemadison13 can you open a new issue. And please don't use it at a project level. The preferred method is a Phar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs more information Further information is requested
Projects
None yet
Development

No branches or pull requests

6 participants