10

For php8.1 and with the latest Magento coding standards we are facing below error while running the static test from CLI and PHPStorm

ERROR: Referenced sniff "PHPCompatibility.FunctionUse.RemovedFunctions" does not exist

6 Answers 6

12

Add the phpcompatibility/php-compatibility ruleset to the composer.json using post-install-cmd:

{
    "scripts": {
        "post-install-cmd": [
            "([ $COMPOSER_DEV_MODE -eq 0 ] || vendor/bin/phpcs --config-set installed_paths ../../magento/magento-coding-standard/,../../phpcompatibility/php-compatibility)"
        ]
    }
}
2
  • This usually works but there is issue with current version of phpcs sometime installed path are blank despite defining it Commented Jun 27, 2022 at 2:39
  • 3
    This should be the accepted answer as it does not require manual changes in any file.
    – EssGee
    Commented Apr 14, 2023 at 12:14
8

This is known issue with Magento coding standards and temporary workaround is to add below code

$resolvedInstalledPaths[] = '/path/to/your/project/vendor/phpcompatibility/php-compatibility/PHPCompatibility';

        $resolvedInstalledPaths[] = $installedPath;
    }

    return $resolvedInstalledPaths;

to

\PHP_CodeSniffer\Util\Standards::getInstalledStandardPaths

1

Run:
vendor/bin/phpcs --config-set installed_paths ../../magento/magento-coding-standard,../../magento/php-compatibility-fork/PHPCompatibility

0

None the suggestions present here helped me to fix GitHub actions. Instead, I've used the following:

  1. Run $ composer require --dev "dealerdirect/phpcodesniffer-composer-installer".

  2. Add in your composer.json the section ->

    "config": {"allow-plugins": {"dealerdirect/phpcodesniffer-composer-installer": true}}
    
  3. If you're using --no-dev flag for composer install, avoid using it! Since coding-standards most of the time are required in Require-Dev.

  4. Remove the package phpcompatibility (if applied to your composer.json)

    $ composer remove phpcompatibility/php-compatibility
    
  5. Remove from script section the following snippet because it won't work for PHP81:

    "scripts": {
        "post-install-cmd": [
            "([ $COMPOSER_DEV_MODE -eq 0 ] || vendor/bin/phpcs --config-set installed_paths ../../magento/magento-coding-standard/,../../phpcompatibility/php-compatibility)"
        ],
        "post-update-cmd": [
            "([ $COMPOSER_DEV_MODE -eq 0 ] || vendor/bin/phpcs --config-set installed_paths ../../magento/magento-coding-standard/,../../phpcompatibility/php-compatibility)"
        ]
    }
    
0

In composer.json your scripts section should include magento/php-compatibility-fork.

Example:

"scripts": {
    "post-install-cmd": [
        "([ $COMPOSER_DEV_MODE -eq 0 ] || vendor/bin/phpcs --config-set installed_paths ../../magento/magento-coding-standard/,../../magento/php-compatibility-fork)",
        "([ $COMPOSER_DEV_MODE -eq 0 ] || vendor/bin/phpcs --config-set default_standard Magento2)"
    ],
    "post-update-cmd": [
        "([ $COMPOSER_DEV_MODE -eq 0 ] || vendor/bin/phpcs --config-set installed_paths ../../magento/magento-coding-standard/,../../magento/php-compatibility-fork)",
        "([ $COMPOSER_DEV_MODE -eq 0 ] || vendor/bin/phpcs --config-set default_standard Magento2)"
    ]
}
0

It appears the PHPCompatibility standards are forked under magento in vendor/magento/php-compatibility-fork/PHPCompatibility. I was able to fix the error in 2.4.6 and 2.4.7 by going into Settings > PHP > Quality Tools > PHP_CodeSniffer

  • Checking Installed standards path and setting path to {project_dir}/vendor/magento/php-compatibility-fork/PHPCompatibility
  • Selecting "Custom" for Coding standard and setting path to {project_dir}/vendor/magento/magento-coding-standard/Magento2/ruleset.xml

For Warden I used the warden CLI Interpreter and used

  • Installed standards path: /opt/project/vendor/magento/php-compatibility-fork/PHPCompatibility
  • Coding standard: /opt/project/vendor/magento/magento-coding-standard/Magento2/ruleset.xml

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.