PHPCSStandards / composer-installer

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

Coding Standard tries itself to install with installPath when it's the root package #19

Closed bastianschwarz closed 7 years ago

bastianschwarz commented 7 years ago

Problem/Motivation

Today, I started to develop my own coding style. Of course, I want to use the same CI tools, including PHPCompatibility. Unfortunately, the installer tries to install the root package by using the install path (which isn't available, since the root package of course doesn't install itself).

Expected behaviour

The installer should install all dependency packages with the install path, but either ignore the root package or install the root package using the repo root.

Actual behaviour

The installer tries to install the root package with its install path:

bastian@bastian-codenamephp:~/workspace/codenamephp/codingstandard$ composer update -v
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Generating autoload files

  [InvalidArgumentException]                                                                                            
  The "/home/bastian/workspace/codenamephp/codingstandard/vendor/codenamephp/codingstandard" directory does not exist.  

Exception trace:
 () at phar:///usr/bin/composer/vendor/symfony/finder/Finder.php:656
 Symfony\Component\Finder\Finder->in() at /home/bastian/workspace/codenamephp/codingstandard/vendor/dealerdirect/phpcodesniffer-composer-installer/src/Plugin.php:255
 Dealerdirect\Composer\Plugin\Installers\PHPCodeSniffer\Plugin->updateInstalledPaths() at /home/bastian/workspace/codenamephp/codingstandard/vendor/dealerdirect/phpcodesniffer-composer-installer/src/Plugin.php:147
 Dealerdirect\Composer\Plugin\Installers\PHPCodeSniffer\Plugin->onDependenciesChangedEvent() at n/a:n/a
 call_user_func() at phar:///usr/bin/composer/src/Composer/EventDispatcher/EventDispatcher.php:171
 Composer\EventDispatcher\EventDispatcher->doDispatch() at phar:///usr/bin/composer/src/Composer/EventDispatcher/EventDispatcher.php:96
 Composer\EventDispatcher\EventDispatcher->dispatchScript() at phar:///usr/bin/composer/src/Composer/Installer.php:307
 Composer\Installer->run() at phar:///usr/bin/composer/src/Composer/Command/UpdateCommand.php:158
 Composer\Command\UpdateCommand->execute() at phar:///usr/bin/composer/vendor/symfony/console/Command/Command.php:257
 Symfony\Component\Console\Command\Command->run() at phar:///usr/bin/composer/vendor/symfony/console/Application.php:850
 Symfony\Component\Console\Application->doRunCommand() at phar:///usr/bin/composer/vendor/symfony/console/Application.php:193
 Symfony\Component\Console\Application->doRun() at phar:///usr/bin/composer/src/Composer/Console/Application.php:227
 Composer\Console\Application->doRun() at phar:///usr/bin/composer/vendor/symfony/console/Application.php:124
 Symfony\Component\Console\Application->run() at phar:///usr/bin/composer/src/Composer/Console/Application.php:100
 Composer\Console\Application->run() at phar:///usr/bin/composer/bin/composer:54
 require() at /usr/bin/composer:24

Steps to reproduce

Create a package with type "type": "phpcodesniffer-standard" and the installer as dependency:

{
  "name": "vendor/package",
  "type": "phpcodesniffer-standard",
  "require": {
    "php": "^7.0",
    "squizlabs/php_codesniffer": "3.0.x-dev as 2.0.0"
  },
  "require-dev": {
    "dealerdirect/phpcodesniffer-composer-installer": "*",
    "frenck/php-compatibility": "*"
  },
  "autoload": {
    "classmap": ["src/main/php"]
  },
  "autoload-dev": {
    "psr-0": {
      "CodenamePHP": ["src/main/php", "src/test/php"]
    }
  }
}

The problem repo will be https://github.com/codenamephp/codingstandard but the code is not comitted yet (obviously)

Proposed changes

The root could either be ignored or installed via the root path.

Ignoring the package would be easy by adding a check for instanceof RootPackageInterface in updateInstalledPaths().

Choosing the correct path could be done by the same instance of check when getting the install path in updateInstalledPaths().

bastianschwarz commented 7 years ago

As I understand, the package adds itself so the coding style so it is also used when running Codesniffer on the package itself, so it is wanted behavior, correct?

I might be able to look into this at the weekend and open a PR (no promises though).

You don't happen to have your formatting settings for usage in Netbeans lying around, do you?

Potherca commented 7 years ago

Hi @bastianschwarz, thanks for reporting this!

I've just discussed this with @frenck and we're going to take a more detailed look at this issue tomorrow (Friday).

Our current thinking is to implement both of your suggested changes:

  1. Add a check to ignore the RootPackageInterface (which should resolve this issue)
  2. Add separate logic to look for sniffs in the RootPackage (see #20)

Well post an update when we've implemented these changes.

bastianschwarz commented 7 years ago

Sounds great, give me a shout if I can do anything to help.

Potherca commented 7 years ago

As you might have noticed we hadn't gotten around to this issue. Your pull-request is much appreciated!

The changes from your PR have been merged and will be released with v0.3.2 as soon as #22 has been merged.