From a2cb6708ab6dc413ec949fbe6af7e607801e4edc Mon Sep 17 00:00:00 2001 From: Dan Wallis Date: Wed, 1 Feb 2023 16:19:13 +0000 Subject: [PATCH] Use a composer plugin to register the standard --- README.md | 16 +--------- composer.json | 8 +++-- composer.lock | 82 +++++++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 86 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 3cfd6c0a..95bd1897 100644 --- a/README.md +++ b/README.md @@ -10,20 +10,6 @@ To use within your Magento 2 project you can use: composer require --dev magento/magento-coding-standard ``` -Due to security, when installed this way the Magento standard for phpcs cannot be added automatically. -You can achieve this by adding the following to your project's `composer.json`: - -```json -"scripts": { - "post-install-cmd": [ - "([ $COMPOSER_DEV_MODE -eq 0 ] || vendor/bin/phpcs --config-set installed_paths ../../magento/magento-coding-standard/)" - ], - "post-update-cmd": [ - "([ $COMPOSER_DEV_MODE -eq 0 ] || vendor/bin/phpcs --config-set installed_paths ../../magento/magento-coding-standard/)" - ] -} -``` - ### Installation for development You can install Magento Coding Standard by cloning this GitHub repo: @@ -122,7 +108,7 @@ The rules from rector that are applied are set inside the config file: `rector.p The option `--dry-run` displays errors found, but code is not automatically fixed. To run rector for `magento` projects you need to: -- Specify the magento path and the autoload file for the magento project: +- Specify the magento path and the autoload file for the magento project: ```bash vendor/bin/rector process MAGENTO_PATH --dry-run --autoload-file MAGENTO_AUTOLOAD_FILE ``` diff --git a/composer.json b/composer.json index 355a66f6..fd6d43a7 100644 --- a/composer.json +++ b/composer.json @@ -9,6 +9,7 @@ "version": "31", "require": { "php": ">=7.4", + "dealerdirect/phpcodesniffer-composer-installer": "^0.7.2 || ^1.0", "webonyx/graphql-php": "^15.0", "ext-simplexml": "*", "ext-dom": "*", @@ -33,8 +34,9 @@ "Magento2Framework\\": "Magento2Framework/" } }, - "scripts": { - "post-install-cmd": "vendor/bin/phpcs --config-set installed_paths ../../..,../../phpcompatibility/php-compatibility/PHPCompatibility", - "post-update-cmd": "vendor/bin/phpcs --config-set installed_paths ../../..,../../phpcompatibility/php-compatibility/PHPCompatibility" + "config": { + "allow-plugins": { + "dealerdirect/phpcodesniffer-composer-installer": true + } } } diff --git a/composer.lock b/composer.lock index f2880864..23393d2e 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,86 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "a1016f46104814a16b090a61a5c2ca2a", + "content-hash": "d5b737bfcab2053b6a04725293a5abff", "packages": [ + { + "name": "dealerdirect/phpcodesniffer-composer-installer", + "version": "v1.0.0", + "source": { + "type": "git", + "url": "https://github.com/PHPCSStandards/composer-installer.git", + "reference": "4be43904336affa5c2f70744a348312336afd0da" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCSStandards/composer-installer/zipball/4be43904336affa5c2f70744a348312336afd0da", + "reference": "4be43904336affa5c2f70744a348312336afd0da", + "shasum": "" + }, + "require": { + "composer-plugin-api": "^1.0 || ^2.0", + "php": ">=5.4", + "squizlabs/php_codesniffer": "^2.0 || ^3.1.0 || ^4.0" + }, + "require-dev": { + "composer/composer": "*", + "ext-json": "*", + "ext-zip": "*", + "php-parallel-lint/php-parallel-lint": "^1.3.1", + "phpcompatibility/php-compatibility": "^9.0", + "yoast/phpunit-polyfills": "^1.0" + }, + "type": "composer-plugin", + "extra": { + "class": "PHPCSStandards\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin" + }, + "autoload": { + "psr-4": { + "PHPCSStandards\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Franck Nijhof", + "email": "franck.nijhof@dealerdirect.com", + "homepage": "http://www.frenck.nl", + "role": "Developer / IT Manager" + }, + { + "name": "Contributors", + "homepage": "https://github.com/PHPCSStandards/composer-installer/graphs/contributors" + } + ], + "description": "PHP_CodeSniffer Standards Composer Installer Plugin", + "homepage": "http://www.dealerdirect.com", + "keywords": [ + "PHPCodeSniffer", + "PHP_CodeSniffer", + "code quality", + "codesniffer", + "composer", + "installer", + "phpcbf", + "phpcs", + "plugin", + "qa", + "quality", + "standard", + "standards", + "style guide", + "stylecheck", + "tests" + ], + "support": { + "issues": "https://github.com/PHPCSStandards/composer-installer/issues", + "source": "https://github.com/PHPCSStandards/composer-installer" + }, + "time": "2023-01-05T11:28:13+00:00" + }, { "name": "phpcompatibility/php-compatibility", "version": "9.3.5", @@ -2053,5 +2131,5 @@ "ext-dom": "*" }, "platform-dev": [], - "plugin-api-version": "2.2.0" + "plugin-api-version": "2.3.0" }