squizlabs / PHP_CodeSniffer

PHP_CodeSniffer tokenizes PHP files and detects violations of a defined set of coding standards.
BSD 3-Clause "New" or "Revised" License
10.67k stars 1.48k forks source link

Composer install fails with Call to a member function findFile() on boolean #1306

Closed felixfbecker closed 7 years ago

felixfbecker commented 7 years ago

Installing the 3.0.x-dev branch results in

PHP Fatal error:  Uncaught Error: Call to a member function findFile() on boolean in /home/ubuntu/.../vendor/squizlabs/php_codesniffer/autoload.php:91
Stack trace:
#0 [internal function]: PHP_CodeSniffer\Autoload::load('Symfony\\Compone...')
#1 phar:///usr/local/bin/composer/vendor/symfony/console/Application.php(854): spl_autoload_call('Symfony\\Compone...')
#2 phar:///usr/local/bin/composer/vendor/symfony/console/Application.php(193): Symfony\Component\Console\Application->doRunCommand(Object(Composer\Command\RunScriptCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#3 phar:///usr/local/bin/composer/src/Composer/Console/Application.php(227): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#4 phar:///usr/local/bin/composer/vendor/symfony/console/Application.php(124): Composer\Console\Application->doRun(Objec in /home/ubuntu/.../vendor/squizlabs/php_codesniffer/autoload.php on line 91

I have to install from the branch because the RC2 is missing an important bug fix, this now broke my builds :/

ddinchev commented 7 years ago

I get a very similar message after updating to the latest 3.0.x-dev:

PHP message: PHP Fatal error:  Uncaught Error: Call to a member function unregister() on boolean in /app/vendor/squizlabs/php_codesniffer/autoload.php:65
Stack trace:
#0 [internal function]: PHP_CodeSniffer\Autoload::load('Go\\ParserReflec...')
#1 /app/vendor/goaop/parser-reflection/src/bootstrap.php(17): spl_autoload_call('Go\\ParserReflec...')
#2 /app/vendor/composer/autoload_real.php(66): require('/app/vendor/goa...')
#3 /app/vendor/composer/autoload_real.php(56): composerRequire35a8a66d127a5aa3a9c6513497d56b06('950e8c5ec01dc90...', '/app/vendor/com...')
#4 /app/vendor/autoload.php(7): ComposerAutoloaderInit35a8a66d127a5aa3a9c6513497d56b06::getLoader()
#5 /app/frontend/web/index.php(3): require('/app/vendor/aut...')
#6 {main}

For me, changing the required version in composer.json to "squizlabs/php_codesniffer": "3.0.0RC2" worked fine (in case anyone looks for a quick solution until branch is fixed).

ddinchev commented 7 years ago

@felixfbecker you could also include CodeSniffer at a specific commit, for now. The one after your needed patch but before the breaking changes:

"squizlabs/php_codesniffer": "dev-master#09dba39a88e327ee75814b921fcae85904562262"

My example is just a random commit from few days ago.

felixfbecker commented 7 years ago

@ddinchev look at the composer.json, that is exactly how it is referenced. Composer doesn't care apparently, and the docs say the feature is not actively supported and bug reports will not be accepted.

gsherwood commented 7 years ago

I'm currently redoing the way autoloading works with composer in the 3.0 branch (started last week as part of #1259) so that's why you're seeing issues. It's a shame the commit-specific inclusion isn't working for you because I think the 3.0 branch might be a bit unstable for a bit longer. I'll try and get it working as soon as I can though.

gsherwood commented 7 years ago

Also note that this was reported here: https://github.com/squizlabs/PHP_CodeSniffer/pull/1322

See my comment for why I can't merge that in. But it's what I'm actively working on.

felixfbecker commented 7 years ago

@gsherwood Thanks for the response. As I said this is pretty urgent because this broke our build and the commit reference is not working. My only other option is to remove this dependency, which would be a huge breaking change as I would have to remove the whole formatting feature.

Could you maybe tag an the old commit e8acf8e029301b0e3ea7e7c9eef0aee914db78bf as RC3 until we have a more stable version again? That one is the one I am trying to pin on, which passes all my tests and includes an important bug fix over RC2.

gsherwood commented 7 years ago

@felixfbecker I've just pushed a change that might fix it for you. Can you test that if you get a chance please.

felixfbecker commented 7 years ago

Works, build is green again, thanks. But I would really like for some way to prevent this in the future (I wasn't aware I couldn't depend on a commit hash like that with Composer).

gsherwood commented 7 years ago

But I would really like for some way to prevent this in the future

Then you'd need to stick to the tagged releases I guess. I don't know much about composer though, so maybe there is a solution in there somewhere.

Thanks for testing it.

cweagans commented 7 years ago

@gsherwood Any chance of another RC release in the near future? I think that would resolve the issue. Or a full 3.0.0 release? Checked the 3.0.0 milestone here to see if there was anywhere I could help out, but there's nothing there.

gsherwood commented 7 years ago

The issue wasn't in the last RC release. I only committed that code last week while I was reworking the autoloader. So if you're already using the 3.0 branch, you can update and get the fix now. If you using RC2, you won't be getting any composer autoloading through PHPCS.