Skip to content

QA - Add PHP Compatibility (adds rules to phpcs)

php-compatibility is a set of sniffs for PHP_CodeSniffer that checks for PHP version compatibility. It will allow you to analyse your code for compatibility with higher and lower versions of PHP.

documentation:

# install
composer require --dev "phpcompatibility/php-compatibility"
vendor/bin/phpcs --config-set installed_paths vendor/phpcompatibility/php-compatibility
     # (1) this last command line must be added in the "post-install-cmd" and "post-update-cmd" of composer.json file.

# Show rules and coding standards
vendor/bin/phpcs --standard=PHPCompatibility <dir>/<file>

vendor/bin/phpcs src/ -p --standard=PHPCompatibility --runtime-set testVersion 7.2-7.4
vendor/bin/phpcs src/ -p --standard=PHPCompatibility --runtime-set testVersion 7.0-

(1) this last command line must be added in the X and y scripts of composer.json

     "scripts": {
+        "install-codestandards": [
+            "\"vendor/bin/phpcs\" --config-set installed_paths vendor/phpcompatibility/php-compatibility"
+        ],
         "auto-scripts": {
             "cache:clear": "symfony-cmd",
             "assets:install %PUBLIC_DIR%": "symfony-cmd"
         },
         "post-install-cmd": [
+            "@install-codestandards"
         ],
         "post-update-cmd": [
+            "@install-codestandards"
         ]
     },

need #27 (closed)

Edited by Fabrice Gangler