PHPCSStandards / composer-installer

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

Allow a string value for extra.phpcodesniffer-search-depth #82

Closed TravisCarden closed 4 years ago

TravisCarden commented 5 years ago

It's impossible to set the extra.phpcodesniffer-search-depth config value from the command line because it strictly enforces an integer type on it, whereas composer config cannot set integer values (see https://github.com/composer/composer/issues/8195):

$ composer init -n
$ composer config extra.phpcodesniffer-search-depth 4
$ cat composer.json
{
    "require": {},
    "extra": {
        "phpcodesniffer-search-depth": "4"
    }
}
$ composer require --dev dealerdirect/phpcodesniffer-composer-installer
Using version ^0.5.0 for dealerdirect/phpcodesniffer-composer-installer
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 2 installs, 0 updates, 0 removals
  - Installing squizlabs/php_codesniffer (3.4.2): Loading from cache
  - Installing dealerdirect/phpcodesniffer-composer-installer (v0.5.0): Loading from cache
Writing lock file
Generating autoload files

Installation failed, reverting ./composer.json to its original content.

  [InvalidArgumentException]
  The value of "phpcodesniffer-search-depth" (in the composer.json "extra".section) must be an integer larger then 0, '4' given.

require [--dev] [--prefer-source] [--prefer-dist] [--no-progress] [--no-suggest] [--no-update] [--no-scripts] [--update-no-dev] [--update-with-dependencies] [--update-with-all-dependencies] [--ignore-platform-reqs] [--prefer-stable] [--prefer-lowest] [--sort-packages] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--apcu-autoloader] [--] [<packages>]...

I currently use the following fairly ugly kludge as a workaround:

sed -i'.bak' 's|"phpcodesniffer-search-depth": "4"|"phpcodesniffer-search-depth": 4|' composer.json && rm composer.json.bak

For its part, I've requested that Composer provide the ability to typecast data on the commandline (again, see https://github.com/composer/composer/issues/8195). On this side, it would be nice if phpcodesniffer-composer-installer would typecast string values to integers. Would the maintainers accept a pull request to that effect?

Potherca commented 5 years ago

Hi! Thank you for reporting this issue!

We would definitely welcome such a contribution but (as you may have noticed from my late response) we don't have much time/energy to spend on this project currently.

So, if you do decide to open an MR, don't feel discouraged if our response is slow!

TravisCarden commented 5 years ago

Thanks, @Potherca! https://github.com/Dealerdirect/phpcodesniffer-composer-installer/pull/85 should do the trick. :)

Potherca commented 4 years ago

The MR has been merged, will be part of the upcoming 0.5.1 release.