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
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)"
]
}
}
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
Run:
vendor/bin/phpcs --config-set installed_paths ../../magento/magento-coding-standard,../../magento/php-compatibility-fork/PHPCompatibility
None the suggestions present here helped me to fix GitHub actions. Instead, I've used the following:
Run $ composer require --dev "dealerdirect/phpcodesniffer-composer-installer"
.
Add in your composer.json the section ->
"config": {"allow-plugins": {"dealerdirect/phpcodesniffer-composer-installer": true}}
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.
Remove the package phpcompatibility (if applied to your composer.json)
$ composer remove phpcompatibility/php-compatibility
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)"
]
}
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)"
]
}
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
{project_dir}/vendor/magento/php-compatibility-fork/PHPCompatibility
{project_dir}/vendor/magento/magento-coding-standard/Magento2/ruleset.xml
For Warden I used the warden CLI Interpreter and used
/opt/project/vendor/magento/php-compatibility-fork/PHPCompatibility
/opt/project/vendor/magento/magento-coding-standard/Magento2/ruleset.xml