dancryer / PHPCI

PHPCI is a free and open source continuous integration tool specifically designed for PHP.
BSD 2-Clause "Simplified" License
2.42k stars 442 forks source link

Adding PHPCS custom standards - adding directory causes errors #589

Open designvoid opened 9 years ago

designvoid commented 9 years ago

Asuming there are the following 3 scenarios when specifying Standards in the config file for PHPCS:

1) Using 1 of defaults (ie PSR2 etc) 2) Using a standard included within the Project 3) Using a standard located outside of the project (elsewhere on server)

The exisitng code on line 187 of PHPCI/Plugin/PhpCodeSniffer.php

if (strpos($this->standard, '/') !== false) {
    $standard = ' --standard='.$this->directory.$this->standard;
} else {
    $standard = ' --standard='.$this->standard;
}

Doesn't handle these 3 scenarios, it adds the project directory to the standard irrespecitive of wether it starts with a leading '/' or not. If you are providing an absolute path there is no need for the leading '/'

I have modified my copy of the file thusly:

if (strpos($this->standard, '/') !== false && substr($this->standard, 0, 1) != '/') {
    $standard = ' --standard='.$this->directory.$this->standard;
} else {
    $standard = ' --standard='.$this->standard;
}

Now it works as expected (to me at least) so I welcome a response from the team as to wether this is correct or not?

robertscherer commented 9 years ago

Seconding this issue - we have solved it by simply copying by copying a special CodeSniffer.conf to the build folder's squizlabs vendor directy using the shell plugin in the setup part of the phpci.yml.

leewillis77 commented 9 years ago

I've just hit this and got thoroughly confused since my server already had phpcs correctly configured. I've temporarily solved it by running vendor/squizlabs/php_codesniffer/scripts/phpcs --config-set installed_paths /usr/local/share/wpcs/ but seems there should be a nicer solution.