phpro / grumphp

A PHP code-quality tool
MIT License
4.15k stars 431 forks source link

Global installation and wrong dependency autoload #83

Closed aaa2000 closed 8 years ago

aaa2000 commented 8 years ago

When the installation of grumphp is global, a wrong dependency could be use by grumphp

Given a global installation of grumphp
Given a project with symfony/console=2.1.0 dependency
When I am in the project directory
And I run:
"""
grumphp run -c grumphp.yml
"""
Then I get the error:
"""
PHP Fatal error:  Call to undefined method Symfony\Component\Console\Helper\Helper::strlen() in /home/USER/.composer/vendor/symfony/console/Helper/ProgressBar.php on line 472
"""

bin/grumphp use the symfony/console=2.1.0 project dependency instead of global symfony/console dependency

At the moment, I do a hack in my global bin/grumphp to autoload only my global autoload

veewee commented 8 years ago

Hello @aaa2000,

Thanks for reporting the issue. I just tested this with following commands:

composer global require phpro/grumphp
mkdir test && cd test
git init
composer require symfony/console:2.1
grumphp configure # Here I added PHPCS as task
grumphp run

I do not retrieve the exception. Can you tell us how to reproduce the described issue?

The global packages are always prepended to the autloader, and should be used before the project packages. Maybe one of the paths is wrong on your system?

Thanks!

aaa2000 commented 8 years ago

I get this error at step grumphp configure.

 grumphp configure -v  

  [InvalidArgumentException]             
  The helper "question" is not defined.  

Exception trace:
 () at /home/user/grumphp-bug-83/vendor/symfony/console/Symfony/Component/Console/Helper/HelperSet.php:79
 Symfony\Component\Console\Helper\HelperSet->get() at /home/user/grumphp-bug-83/vendor/symfony/console/Symfony/Component/Console/Command/Command.php:541
 Symfony\Component\Console\Command\Command->getHelper() at /home/user/.composer/vendor/phpro/grumphp/src/GrumPHP/Console/Command/ConfigureCommand.php:119
 GrumPHP\Console\Command\ConfigureCommand->buildConfiguration() at /home/user/.composer/vendor/phpro/grumphp/src/GrumPHP/Console/Command/ConfigureCommand.php:89
 GrumPHP\Console\Command\ConfigureCommand->execute() at /home/user/grumphp-bug-83/vendor/symfony/console/Symfony/Component/Console/Command/Command.php:239
 Symfony\Component\Console\Command\Command->run() at /home/user/grumphp-bug-83/vendor/symfony/console/Symfony/Component/Console/Application.php:193
 Symfony\Component\Console\Application->doRun() at /home/user/grumphp-bug-83/vendor/symfony/console/Symfony/Component/Console/Application.php:106
 Symfony\Component\Console\Application->run() at /home/user/.composer/vendor/phpro/grumphp/bin/grumphp:32

configure

My global package composer global show -i.

...
phpro/grumphp                     v0.7.0 A composer plugin that enables source code quality checks.
symfony/console                   v3.0.0 Symfony Console Component
...

I will try tomorrow the steps on a VM or another computer, and I will try another version of grumphp.

aaa2000 commented 8 years ago

I can't reproduce the bug on the VM. You are right, I certainly have one of the paths wrong on my system. Sorry for the inconvenience.

Thanks.

aaa2000 commented 8 years ago

I had the problem because I have an auto_prepend_file with the global composer autoload file in order to use var_dumper. https://symfony.com/doc/current/components/var_dumper/introduction.html

sudo sh -c "echo 'auto_prepend_file = \"/home/vagrant/.composer/vendor/autoload.php\"' > /etc/php5/cli/conf.d/30-global_composer.ini"
veewee commented 8 years ago

Cool, did not know about that one. But indeed: that can result in some strange behaviour. I don't think that we can do something about that: the file gets loaded and next de project file is prepended to the autoloading queue. So the project autoload will win.