PHPCSStandards / composer-installer

Composer installer for PHP_CodeSniffer coding standards
https://packagist.org/packages/dealerdirect/phpcodesniffer-composer-installer
MIT License
559 stars 36 forks source link

phpcs: Exit Code: 127 (Command not found) on every Composer command #48

Closed kenorb closed 6 years ago

kenorb commented 6 years ago

Problem/Motivation

After installed "dealerdirect/phpcodesniffer-composer-installer": "^0.4.3", my Composer getting error about phpcs command not being found.

This happens, when I am working with multiple bin-dir folders. Normally I've got COMPOSER_BIN_DIR pointed to /usr/local/bin, but in some shell instances, I don't have. After installing this package, now every composer is producing the error.

Expected behaviour

The processing should be ignored when the binary can't be found.

Actual behaviour

$ composer global show
Changed current directory to /Users/kenorb/.composer

  [Symfony\Component\Process\Exception\ProcessFailedException]                                        
  The command "'/Users/kenorb/.composer/vendor/bin/phpcs' '--config-show' 'installed_paths'" failed.  

  Exit Code: 127(Command not found)                                                                   

  Working directory: /Users/kenorb/.composer                                                          

  Output:                                                                                             
  ================                                                                                    

  Error Output:                                                                                       
  ================                                                                                    
  sh: /Users/kenorb/.composer/vendor/bin/phpcs: No such file or directory                             

global <command-name> [<args>]...

Exception trace:
 () at phar:///usr/local/Cellar/composer/1.6.3/libexec/composer.phar/vendor/symfony/process/Process.php:221
 Symfony\Component\Process\Process->mustRun() at /Users/kenorb/.composer/vendor/dealerdirect/phpcodesniffer-composer-installer/src/Plugin.php:183
 Dealerdirect\Composer\Plugin\Installers\PHPCodeSniffer\Plugin->loadInstalledPaths() at /Users/kenorb/.composer/vendor/dealerdirect/phpcodesniffer-composer-installer/src/Plugin.php:121
 Dealerdirect\Composer\Plugin\Installers\PHPCodeSniffer\Plugin->init() at /Users/kenorb/.composer/vendor/dealerdirect/phpcodesniffer-composer-installer/src/Plugin.php:103
 Dealerdirect\Composer\Plugin\Installers\PHPCodeSniffer\Plugin->activate() at phar:///usr/local/Cellar/composer/1.6.3/libexec/composer.phar/src/Composer/Plugin/PluginManager.php:236
 Composer\Plugin\PluginManager->addPlugin() at phar:///usr/local/Cellar/composer/1.6.3/libexec/composer.phar/src/Composer/Plugin/PluginManager.php:205
 Composer\Plugin\PluginManager->registerPackage() at phar:///usr/local/Cellar/composer/1.6.3/libexec/composer.phar/src/Composer/Plugin/PluginManager.php:261
...

Steps to reproduce

COMPOSER_BIN_DIR="/usr/local/bin" composer global require dealerdirect/phpcodesniffer-composer-installer:^0.4.3
composer -v global show

Proposed changes

The plugin should be less invasive.

Potherca commented 6 years ago

Hi! Thank you for taking the time to report this.

This behaviour seems to be caused by the fact that the plugin functionality is called when it should not be. In other words, the plugin is triggered for an event it is not registered for.

The root cause is that the (public) activate function calls the (private) init function which, in turn, triggered calling PHPCS (in the loadInstalledPaths function).

A potential solution would be simply move the init call into the onDependenciesChangedEvent function.

That way init is only called when the plugin is about to be used, rather than on any composer command.

jrfnl commented 6 years ago

Looks like PR #51 addresses this issue.

frenck commented 6 years ago

This is indeed addressed by #51, which has been merged in and will be part of the next release.