WordPress / WordPress-Coding-Standards

PHP_CodeSniffer rules (sniffs) to enforce WordPress coding conventions
MIT License
2.53k stars 471 forks source link

Class 'WordPress\AbstractArrayAssignmentRestrictionsSniff' not found #1087

Closed guillaumemolter closed 7 years ago

guillaumemolter commented 7 years ago

Context:

Error:

PHP Fatal error:  Class 'WordPress\AbstractArrayAssignmentRestrictionsSniff' not found in /Users/guillaumemolter/Dev/vvv/www/sites/htdocs/wp-content/plugins/plugin-disable-sidebar/vendor/wp-coding-standards/wpcs/WordPress/Sniffs/Arrays/ArrayAssignmentRestrictionsSniff.php on line 30
PHP Stack trace:
PHP   1. {main}() /Users/guillaumemolter/Dev/vvv/www/sites/htdocs/wp-content/plugins/plugin-disable-sidebar/vendor/squizlabs/php_codesniffer/bin/phpcs:0
PHP   2. PHP_CodeSniffer\Runner->runPHPCS() /Users/guillaumemolter/Dev/vvv/www/sites/htdocs/wp-content/plugins/plugin-disable-sidebar/vendor/squizlabs/php_codesniffer/bin/phpcs:18
PHP   3. PHP_CodeSniffer\Runner->init() /Users/guillaumemolter/Dev/vvv/www/sites/htdocs/wp-content/plugins/plugin-disable-sidebar/vendor/squizlabs/php_codesniffer/src/Runner.php:70
PHP   4. PHP_CodeSniffer\Ruleset->__construct() /Users/guillaumemolter/Dev/vvv/www/sites/htdocs/wp-content/plugins/plugin-disable-sidebar/vendor/squizlabs/php_codesniffer/src/Runner.php:294
PHP   5. PHP_CodeSniffer\Ruleset->registerSniffs() /Users/guillaumemolter/Dev/vvv/www/sites/htdocs/wp-content/plugins/plugin-disable-sidebar/vendor/squizlabs/php_codesniffer/src/Ruleset.php:206
PHP   6. PHP_CodeSniffer\Autoload::loadFile() /Users/guillaumemolter/Dev/vvv/www/sites/htdocs/wp-content/plugins/plugin-disable-sidebar/vendor/squizlabs/php_codesniffer/src/Ruleset.php:1094
PHP   7. include() /Users/guillaumemolter/Dev/vvv/www/sites/htdocs/wp-content/plugins/plugin-disable-sidebar/vendor/squizlabs/php_codesniffer/autoload.php:167

Fatal error: Class 'WordPress\AbstractArrayAssignmentRestrictionsSniff' not found in /Users/guillaumemolter/Dev/vvv/www/sites/htdocs/wp-content/plugins/plugin-disable-sidebar/vendor/wp-coding-standards/wpcs/WordPress/Sniffs/Arrays/ArrayAssignmentRestrictionsSniff.php on line 30

Call Stack:
    0.0004     353304   1. {main}() /Users/guillaumemolter/Dev/vvv/www/sites/htdocs/wp-content/plugins/plugin-disable-sidebar/vendor/squizlabs/php_codesniffer/bin/phpcs:0
    0.0050     570272   2. PHP_CodeSniffer\Runner->runPHPCS() /Users/guillaumemolter/Dev/vvv/www/sites/htdocs/wp-content/plugins/plugin-disable-sidebar/vendor/squizlabs/php_codesniffer/bin/phpcs:18
    0.0190     871608   3. PHP_CodeSniffer\Runner->init() /Users/guillaumemolter/Dev/vvv/www/sites/htdocs/wp-content/plugins/plugin-disable-sidebar/vendor/squizlabs/php_codesniffer/src/Runner.php:70
    0.0261    1145408   4. PHP_CodeSniffer\Ruleset->__construct() /Users/guillaumemolter/Dev/vvv/www/sites/htdocs/wp-content/plugins/plugin-disable-sidebar/vendor/squizlabs/php_codesniffer/src/Runner.php:294
    0.1185    1611952   5. PHP_CodeSniffer\Ruleset->registerSniffs() /Users/guillaumemolter/Dev/vvv/www/sites/htdocs/wp-content/plugins/plugin-disable-sidebar/vendor/squizlabs/php_codesniffer/src/Ruleset.php:206
    0.1185    1612008   6. PHP_CodeSniffer\Autoload::loadFile() /Users/guillaumemolter/Dev/vvv/www/sites/htdocs/wp-content/plugins/plugin-disable-sidebar/vendor/squizlabs/php_codesniffer/src/Ruleset.php:1094
    0.1187    1630416   7. include('/Users/guillaumemolter/Dev/vvv/www/sites/htdocs/wp-content/plugins/plugin-disable-sidebar/vendor/wp-coding-standards/wpcs/WordPress/Sniffs/Arrays/ArrayAssignmentRestrictionsSniff.php') /Users/guillaumemolter/Dev/vvv/www/sites/htdocs/wp-content/plugins/plugin-disable-sidebar/vendor/squizlabs/php_codesniffer/autoload.php:167

plugin-disable-sidebar $ vendor/bin/phpcs ./
PHP Fatal error:  Class 'WordPress\AbstractArrayAssignmentRestrictionsSniff' not found in /Users/guillaumemolter/Dev/vvv/www/sites/htdocs/wp-content/plugins/plugin-disable-sidebar/vendor/wp-coding-standards/wpcs/WordPress/Sniffs/Arrays/ArrayAssignmentRestrictionsSniff.php on line 30
PHP Stack trace:
PHP   1. {main}() /Users/guillaumemolter/Dev/vvv/www/sites/htdocs/wp-content/plugins/plugin-disable-sidebar/vendor/squizlabs/php_codesniffer/bin/phpcs:0
PHP   2. PHP_CodeSniffer\Runner->runPHPCS() /Users/guillaumemolter/Dev/vvv/www/sites/htdocs/wp-content/plugins/plugin-disable-sidebar/vendor/squizlabs/php_codesniffer/bin/phpcs:18
PHP   3. PHP_CodeSniffer\Runner->init() /Users/guillaumemolter/Dev/vvv/www/sites/htdocs/wp-content/plugins/plugin-disable-sidebar/vendor/squizlabs/php_codesniffer/src/Runner.php:70
PHP   4. PHP_CodeSniffer\Ruleset->__construct() /Users/guillaumemolter/Dev/vvv/www/sites/htdocs/wp-content/plugins/plugin-disable-sidebar/vendor/squizlabs/php_codesniffer/src/Runner.php:294
PHP   5. PHP_CodeSniffer\Ruleset->registerSniffs() /Users/guillaumemolter/Dev/vvv/www/sites/htdocs/wp-content/plugins/plugin-disable-sidebar/vendor/squizlabs/php_codesniffer/src/Ruleset.php:206
PHP   6. PHP_CodeSniffer\Autoload::loadFile() /Users/guillaumemolter/Dev/vvv/www/sites/htdocs/wp-content/plugins/plugin-disable-sidebar/vendor/squizlabs/php_codesniffer/src/Ruleset.php:1094
PHP   7. include() /Users/guillaumemolter/Dev/vvv/www/sites/htdocs/wp-content/plugins/plugin-disable-sidebar/vendor/squizlabs/php_codesniffer/autoload.php:167

Fatal error: Class 'WordPress\AbstractArrayAssignmentRestrictionsSniff' not found in /Users/guillaumemolter/Dev/vvv/www/sites/htdocs/wp-content/plugins/plugin-disable-sidebar/vendor/wp-coding-standards/wpcs/WordPress/Sniffs/Arrays/ArrayAssignmentRestrictionsSniff.php on line 30

Call Stack:
    0.0003     353336   1. {main}() /Users/guillaumemolter/Dev/vvv/www/sites/htdocs/wp-content/plugins/plugin-disable-sidebar/vendor/squizlabs/php_codesniffer/bin/phpcs:0
    0.0041     570304   2. PHP_CodeSniffer\Runner->runPHPCS() /Users/guillaumemolter/Dev/vvv/www/sites/htdocs/wp-content/plugins/plugin-disable-sidebar/vendor/squizlabs/php_codesniffer/bin/phpcs:18
    0.0197     925472   3. PHP_CodeSniffer\Runner->init() /Users/guillaumemolter/Dev/vvv/www/sites/htdocs/wp-content/plugins/plugin-disable-sidebar/vendor/squizlabs/php_codesniffer/src/Runner.php:70
    0.0233    1146264   4. PHP_CodeSniffer\Ruleset->__construct() /Users/guillaumemolter/Dev/vvv/www/sites/htdocs/wp-content/plugins/plugin-disable-sidebar/vendor/squizlabs/php_codesniffer/src/Runner.php:294
    0.1043    1612432   5. PHP_CodeSniffer\Ruleset->registerSniffs() /Users/guillaumemolter/Dev/vvv/www/sites/htdocs/wp-content/plugins/plugin-disable-sidebar/vendor/squizlabs/php_codesniffer/src/Ruleset.php:206
    0.1043    1612488   6. PHP_CodeSniffer\Autoload::loadFile() /Users/guillaumemolter/Dev/vvv/www/sites/htdocs/wp-content/plugins/plugin-disable-sidebar/vendor/squizlabs/php_codesniffer/src/Ruleset.php:1094
    0.1045    1630896   7. include('/Users/guillaumemolter/Dev/vvv/www/sites/htdocs/wp-content/plugins/plugin-disable-sidebar/vendor/wp-coding-standards/wpcs/WordPress/Sniffs/Arrays/ArrayAssignmentRestrictionsSniff.php') /Users/guillaumemolter/Dev/vvv/www/sites/htdocs/wp-content/plugins/plugin-disable-sidebar/vendor/squizlabs/php_codesniffer/autoload.php:167
guillaumemolter commented 7 years ago

Downgrading to squizlabs/php_codesniffer:2.9.1 fixes the issue.

jrfnl commented 7 years ago

@guillaumemolter I have a slight suspicion of why this is occurring for you, but I need more info to be sure.

  1. When you run the composer install && vendor/bin/phpcs command, what version of PHPCS did this resolve to ?
  2. Can you share the custom ruleset you are using ?
  3. Probably not relevant, but just in case: On which PHP version are you running PHPCS ?
guillaumemolter commented 7 years ago

@jrfnl

  1. Resolved to 3.0.2, rolling back to 2.9.1 fixed the issue.
  2. See bellow
  3. PHP 5.6.30 on my Mac and 7.0.4 on CircleCI

Ruleset:

<?xml version="1.0"?>
<ruleset name="HSPH WordPress Coding Standards">
    <config name="installed_paths" value="vendor/wp-coding-standards/wpcs"/>
    <exclude-pattern>*/vendor/*</exclude-pattern>
    <exclude-pattern>*/assets/*</exclude-pattern>
    <arg name="extensions" value="php"/>
    <!-- Include the WordPress ruleset, with exclusions. -->
    <rule ref="WordPress"></rule>
    <rule ref="WordPress.VIP">
        <exclude name="WordPress.VIP.PostsPerPage" />
        <exclude name="WordPress.VIP.RestrictedFunctions" />
    </rule>
    <rule ref="WordPress.WP.I18n">
        <properties>
            <property name="text_domain" type="array" value="hsph-plugin-custom-sidebar" />
        </properties>
    </rule>
    <rule ref="WordPress.WP.DeprecatedFunctions">
        <properties>
            <property name="minimum_supported_version" value="4.8" />
        </properties>
    </rule>
    <rule ref="WordPress.Files.FileName">
        <properties>
            <property name="is_theme" value="false" />
        </properties>
    </rule>
</ruleset>
jrfnl commented 7 years ago

Ok, this confirmed my suspicion. This is a known upstream issue - see: https://github.com/squizlabs/PHP_CodeSniffer/issues/1582

In the mean time, it can easily be solved for you with a minor adjustment to your ruleset.

The WordPress ruleset already includes the WordPress-VIP ruleset, so there is no need to include it separately. Moving the exclusions you have up into the WordPress block should fix this.

In other words, replace :

    <rule ref="WordPress"></rule>
    <rule ref="WordPress.VIP">
        <exclude name="WordPress.VIP.PostsPerPage" />
        <exclude name="WordPress.VIP.RestrictedFunctions" />
    </rule>

with:

    <rule ref="WordPress">
        <exclude name="WordPress.VIP.PostsPerPage" />
        <exclude name="WordPress.VIP.RestrictedFunctions" />
    </rule>

On a completely unrelated side-note: happy to see you're using the new custom properties in your ruleset. You may want to add WordPress.NamingConventions.PrefixAllGlobals / prefixes and minimum_supported_version for WordPress.WP.DeprecatedClasses + WordPress.WP.DeprecatedParameters (all newly introduced in 0.12.0) For more info: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties

guillaumemolter commented 7 years ago

@jrfnl Ok thanks for the explanation. I've implemented the change to our ruleset. It makes sense when you think about it for more than 10 seconds :-). However this didn't fix the issue. How would I fix the issue via our ruleset? I can also keep using 0.12 for now.

Re custom prop: We welcome anything that can make our code more standard, future-proof and secure. I cannot stress enough how much our code base quality has improved since we have decided to strictly enforce WPCS using PHPCS and your tool. So thank you for all the good work and dedication.

jrfnl commented 7 years ago

However this didn't fix the issue. How would I fix the issue via our ruleset?

@guillaumemolter I've run some tests with your ruleset and I cannot reproduce the issue as long as you made the adjustment I suggested.

The only error I manage to get is: ERROR: You must supply at least one file or directory to process.

And that's because neither the ruleset nor the command you supplied tell PHPCS which files to scan. Changing the command to vendor/bin/phpcs . solved that and gave me the normal PHPCS report without errors.

Note: I didn't use Composer for the tests, but that shouldn't make any difference.

Ruleset I used:

<?xml version="1.0"?>
<ruleset name="HSPH WordPress Coding Standards">
    <config name="installed_paths" value="path/to/my/phpcs/install"/>
    <exclude-pattern>*/vendor/*</exclude-pattern>
    <exclude-pattern>*/assets/*</exclude-pattern>
    <arg name="extensions" value="php"/>
    <!-- Include the WordPress ruleset, with exclusions. -->
    <rule ref="WordPress">
        <exclude name="WordPress.VIP.PostsPerPage" />
        <exclude name="WordPress.VIP.RestrictedFunctions" />
    </rule>
    <rule ref="WordPress.WP.I18n">
        <properties>
            <property name="text_domain" type="array" value="hsph-plugin-custom-sidebar" />
        </properties>
    </rule>
    <rule ref="WordPress.WP.DeprecatedFunctions">
        <properties>
            <property name="minimum_supported_version" value="4.8" />
        </properties>
    </rule>
    <rule ref="WordPress.Files.FileName">
        <properties>
            <property name="is_theme" value="false" />
        </properties>
    </rule>
</ruleset>
guillaumemolter commented 7 years ago

I'm sorry but it still fails on both my computer and CircleCi. Yes the command was a typo from me, I've edited the OP with the correct command I actually use.

Here is my new ruleset (you will notice the new custom props :-P):

<?xml version="1.0"?>
<ruleset name="HSPH WordPress Coding Standards">
    <config name="installed_paths" value="vendor/wp-coding-standards/wpcs"/>
    <exclude-pattern>*/vendor/*</exclude-pattern>
    <exclude-pattern>*/assets/*</exclude-pattern>
    <arg name="extensions" value="php"/>
    <!-- Include the WordPress ruleset, with exclusions. -->
    <rule ref="WordPress">
        <exclude name="WordPress.VIP.PostsPerPage" />
        <exclude name="WordPress.VIP.RestrictedFunctions" />
    </rule>
    <rule ref="WordPress.WP.I18n">
        <properties>
            <property name="text_domain" type="array" value="hsph-plugin-custom-sidebar" />
        </properties>
    </rule>
    <rule ref="WordPress.NamingConventions.PrefixAllGlobals">
        <properties>
            <property name="prefixes" type="array" value="hsph" />
        </properties>
    </rule>
    <rule ref="WordPress.WP.DeprecatedFunctions">
        <properties>
            <property name="minimum_supported_version" value="4.8" />
        </properties>
    </rule>
    <rule ref="WordPress.WP.DeprecatedParameters">
        <properties>
            <property name="minimum_supported_version" value="4.8" />
        </properties>
    </rule>
    <rule ref="WordPress.WP.DeprecatedClasses">
        <properties>
            <property name="minimum_supported_version" value="4.8" />
        </properties>
    </rule>
    <rule ref="WordPress.Files.FileName">
        <properties>
            <property name="is_theme" value="false" />
        </properties>
    </rule>
</ruleset>

If it can help the composer lock file:

{
    "_readme": [
        "This file locks the dependencies of your project to a known state",
        "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
        "This file is @generated automatically"
    ],
    "content-hash": "9201a9e374324fceb9c9c0cc41e250e4",
    "packages": [
        {
            "name": "composer/installers",
            "version": "v1.3.0",
            "source": {
                "type": "git",
                "url": "https://github.com/composer/installers.git",
                "reference": "79ad876c7498c0bbfe7eed065b8651c93bfd6045"
            },
            "dist": {
                "type": "zip",
                "url": "https://api.github.com/repos/composer/installers/zipball/79ad876c7498c0bbfe7eed065b8651c93bfd6045",
                "reference": "79ad876c7498c0bbfe7eed065b8651c93bfd6045",
                "shasum": ""
            },
            "require": {
                "composer-plugin-api": "^1.0"
            },
            "replace": {
                "roundcube/plugin-installer": "*",
                "shama/baton": "*"
            },
            "require-dev": {
                "composer/composer": "1.0.*@dev",
                "phpunit/phpunit": "4.1.*"
            },
            "type": "composer-plugin",
            "extra": {
                "class": "Composer\\Installers\\Plugin",
                "branch-alias": {
                    "dev-master": "1.0-dev"
                }
            },
            "autoload": {
                "psr-4": {
                    "Composer\\Installers\\": "src/Composer/Installers"
                }
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "MIT"
            ],
            "authors": [
                {
                    "name": "Kyle Robinson Young",
                    "email": "kyle@dontkry.com",
                    "homepage": "https://github.com/shama"
                }
            ],
            "description": "A multi-framework Composer library installer",
            "homepage": "https://composer.github.io/installers/",
            "keywords": [
                "Craft",
                "Dolibarr",
                "Eliasis",
                "Hurad",
                "ImageCMS",
                "Kanboard",
                "MODX Evo",
                "Mautic",
                "Maya",
                "OXID",
                "Plentymarkets",
                "Porto",
                "RadPHP",
                "SMF",
                "Thelia",
                "WolfCMS",
                "agl",
                "aimeos",
                "annotatecms",
                "attogram",
                "bitrix",
                "cakephp",
                "chef",
                "cockpit",
                "codeigniter",
                "concrete5",
                "croogo",
                "dokuwiki",
                "drupal",
                "elgg",
                "expressionengine",
                "fuelphp",
                "grav",
                "installer",
                "itop",
                "joomla",
                "kohana",
                "laravel",
                "lavalite",
                "lithium",
                "magento",
                "mako",
                "mediawiki",
                "modulework",
                "moodle",
                "phpbb",
                "piwik",
                "ppi",
                "puppet",
                "reindex",
                "roundcube",
                "shopware",
                "silverstripe",
                "sydes",
                "symfony",
                "typo3",
                "wordpress",
                "yawik",
                "zend",
                "zikula"
            ],
            "time": "2017-04-24T06:37:16+00:00"
        }
    ],
    "packages-dev": [
        {
            "name": "squizlabs/php_codesniffer",
            "version": "3.0.2",
            "source": {
                "type": "git",
                "url": "https://github.com/squizlabs/PHP_CodeSniffer.git",
                "reference": "c7594a88ae75401e8f8d0bd4deb8431b39045c51"
            },
            "dist": {
                "type": "zip",
                "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/c7594a88ae75401e8f8d0bd4deb8431b39045c51",
                "reference": "c7594a88ae75401e8f8d0bd4deb8431b39045c51",
                "shasum": ""
            },
            "require": {
                "ext-simplexml": "*",
                "ext-tokenizer": "*",
                "ext-xmlwriter": "*",
                "php": ">=5.4.0"
            },
            "require-dev": {
                "phpunit/phpunit": "~4.0"
            },
            "bin": [
                "bin/phpcs",
                "bin/phpcbf"
            ],
            "type": "library",
            "extra": {
                "branch-alias": {
                    "dev-master": "3.x-dev"
                }
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "BSD-3-Clause"
            ],
            "authors": [
                {
                    "name": "Greg Sherwood",
                    "role": "lead"
                }
            ],
            "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.",
            "homepage": "http://www.squizlabs.com/php-codesniffer",
            "keywords": [
                "phpcs",
                "standards"
            ],
            "time": "2017-07-18T01:12:32+00:00"
        },
        {
            "name": "wp-coding-standards/wpcs",
            "version": "dev-master",
            "source": {
                "type": "git",
                "url": "https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards.git",
                "reference": "2d693836586866412dd910ede4b097a8445222cb"
            },
            "dist": {
                "type": "zip",
                "url": "https://api.github.com/repos/WordPress-Coding-Standards/WordPress-Coding-Standards/zipball/2d693836586866412dd910ede4b097a8445222cb",
                "reference": "2d693836586866412dd910ede4b097a8445222cb",
                "shasum": ""
            },
            "require": {
                "php": ">=5.3",
                "squizlabs/php_codesniffer": "^2.9.0 || ^3.0.2"
            },
            "suggest": {
                "dealerdirect/phpcodesniffer-composer-installer": "^0.4.1"
            },
            "type": "phpcodesniffer-standard",
            "scripts": {
                "post-install-cmd": [
                    "\"vendor/bin/phpcs\" --config-set installed_paths ../../.."
                ],
                "post-update-cmd": [
                    "\"vendor/bin/phpcs\" --config-set installed_paths ../../.."
                ]
            },
            "license": [
                "MIT"
            ],
            "authors": [
                {
                    "name": "Contributors",
                    "homepage": "https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/graphs/contributors"
                }
            ],
            "description": "PHP_CodeSniffer rules (sniffs) to enforce WordPress coding conventions",
            "keywords": [
                "WordPress",
                "phpcs",
                "standards"
            ],
            "support": {
                "issues": "https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues",
                "wiki": "https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki",
                "source": "https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards"
            },
            "time": "2017-08-03T02:00:57+00:00"
        }
    ],
    "aliases": [],
    "minimum-stability": "stable",
    "stability-flags": {
        "wp-coding-standards/wpcs": 20
    },
    "prefer-stable": false,
    "prefer-lowest": false,
    "platform": [],
    "platform-dev": []
}

And CircleCi's composer install output:

composer install --no-interaction

Loading composer repositories with package information
Reading composer.json of wp-coding-standards/wpcs (2013-10-06)
Reading composer.json of wp-coding-standards/wpcs (2013-06-11)
Reading composer.json of wp-coding-standards/wpcs (0.13.0)
Reading composer.json of wp-coding-standards/wpcs (0.12.0)
Reading composer.json of wp-coding-standards/wpcs (0.11.0)
Reading composer.json of wp-coding-standards/wpcs (0.10.0)
Reading composer.json of wp-coding-standards/wpcs (0.9.0)
Reading composer.json of wp-coding-standards/wpcs (0.8.0)
Reading composer.json of wp-coding-standards/wpcs (0.7.1)
Reading composer.json of wp-coding-standards/wpcs (0.7.0)
Reading composer.json of wp-coding-standards/wpcs (0.6.0)
Reading composer.json of wp-coding-standards/wpcs (0.5.0)
Reading composer.json of wp-coding-standards/wpcs (0.4.0)
Reading composer.json of wp-coding-standards/wpcs (0.3.0)                                                         Reading composer.json of wp-coding-standards/wpcs (WAIT-PHPCS/feature/enable-unused-param-check)
Reading composer.json of wp-coding-standards/wpcs (develop)
Reading composer.json of wp-coding-standards/wpcs (feature/improve-performance)
Reading composer.json of wp-coding-standards/wpcs (feature/issue-607-extra-rules-part2)
Reading composer.json of wp-coding-standards/wpcs (feature/lint-dogfooding)
Reading composer.json of wp-coding-standards/wpcs (feature/pending-pull-requests)
Reading composer.json of wp-coding-standards/wpcs (feature/547-spacing-before-returntype)
Reading composer.json of wp-coding-standards/wpcs (gj/title-attributes)
Reading composer.json of wp-coding-standards/wpcs (issue-191)
Reading composer.json of wp-coding-standards/wpcs (issue/124)
Reading composer.json of wp-coding-standards/wpcs (master)                                                             Updating dependencies (including require-dev)
Package operations: 3 installs, 0 updates, 0 removals
  - Installing composer/installers (v1.3.0): Downloading (connecting...)Downloading (0%)           Downloading (10%)Downloading (15%)Downloading (25%)Downloading (30%)Downloading (45%)Downloading (50%)Downloading (60%)Downloading (65%)Downloading (75%)Downloading (80%)Downloading (85%)Downloading (95%)Downloading (100%)
  - Installing squizlabs/php_codesniffer (3.0.2): Downloading (connecting...)Downloading (0%)           Downloading (5%)Downloading (10%)Downloading (15%)Downloading (20%)Downloading (25%)Downloading (30%)Downloading (35%)Downloading (40%)Downloading (45%)Downloading (50%)Downloading (55%)Downloading (60%)Downloading (65%)Downloading (70%)Downloading (75%)Downloading (80%)Downloading (85%)Downloading (90%)Downloading (95%)Downloading (100%)
  - Installing wp-coding-standards/wpcs (dev-master 2d69383): Cloning 2d69383658 from cache
wp-coding-standards/wpcs suggests installing dealerdirect/phpcodesniffer-composer-installer (^0.4.1)
Writing lock file
Generating autoload files

[JRF: Edited the code block for readability]

jrfnl commented 7 years ago

@guillaumemolter What about your composer.json file ? I've tested (again) with the updated ruleset and still cannot reproduce the issue, so I'm wondering if it is related to your Composer setup. The fact that CircleCI does not easily seem to be able to determine the correct version to use for WPCS - even though it does seem to use the right commit in the end - also indicates a potential issue with the composer setup.

The ruleset itself is fine the way it is now and should not cause the fatal error.

Here is my new ruleset (you will notice the new custom props :-P):

:+1:

jrfnl commented 7 years ago

Hang on... I seem to have found the issue.

jrfnl commented 7 years ago

Ok, this is an upstream issue and we'll need to report it there. Jolly, you've found another bug with the autoloader....

Apparently, if installed_paths is set via the ruleset, things go haywire and PHPCS does not load "our" <autoload> file.

The simplest solution for now would be to install the suggested Composer plugin - dealerdirect/phpcodesniffer-composer-installer:^0.4.1 - to handle the installed_paths config for you. You could then remove the <config...> directive for this from your ruleset, though based on my tests, leaving it in should do no harm either.

Let me know if that solves it for you.

ervasive commented 7 years ago

Can confirm, installation of dealerdirect/phpcodesniffer-composer-installer solved the issue for me.

jrfnl commented 7 years ago

@ervasive Thanks for letting us know.

jrfnl commented 7 years ago

I've reported the underlying issue upstream: https://github.com/squizlabs/PHP_CodeSniffer/issues/1591

and pulled a temporary fix for now: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/pull/1090

jrfnl commented 7 years ago

FYI: version 0.13.1 has just been released and contains a patch for this issue.

guillaumemolter commented 7 years ago

@jrfnl sorry I was afk for the weekend. I can confirm that 0.13.1 solved the issue on my end.

jrfnl commented 7 years ago

@guillaumemolter Glad to hear it & thanks for confirming!

alexander-akait commented 7 years ago

@jrfnl upgrade to 0.13.1 doesn't solve issue :disappointed:

jrfnl commented 7 years ago

@evilebottnawi Actually it does solve this issue, but you might be experiencing a different issue. Please open a new issue for your problem detailing the ruleset you are using and the PHPCS, WPCS and PHP versions involved.

Or if you are sure this is the same issue, make sure you've read the whole thread and then add any pertinent information.

alexander-akait commented 7 years ago

@jrfnl thanks for answer. Same issue. Adding this line in my ruleset.xml fix this problem:

<autoload>./vendor/wp-coding-standards/wpcs/WordPress/PHPCSAliases.php</autoload>
jrfnl commented 7 years ago

@evilebottnawi

In this thread we've come across two different issues which are both upstream PHPCS issues to solve:

Both issues still need to be fixed upstream.

The first issue can be solved locally by either - as you did - including the autoloader yourself or by including a complete ruleset and excluding the categories you don't want.

The second issue can be solved by using the DealerDirect Composer plugin, but is also (temporarily) patched via 0.13.1.

There is nothing more we can do in WPCS in this respect.

jrfnl commented 7 years ago

PHPCS failing to load arbitrary class files in a standard when the installed_paths is set via the ruleset and there is no installed_paths set in the PHPCodeSniffer.conf file

FYI: a patch for this part of the issue has just been merged upstream, so should be included in the PHPCS 3.1.0 release.