From faca601f3b9c7c2d86084430142a05cd89b76c63 Mon Sep 17 00:00:00 2001
From: Dan Wallis <dan@wallis.nz>
Date: Tue, 10 Sep 2024 20:25:19 +0100
Subject: [PATCH] Use a composer plugin to register the standard

---
 README.md     | 16 +---------------
 composer.json |  7 ++-----
 composer.lock |  6 +++---
 3 files changed, 6 insertions(+), 23 deletions(-)

diff --git a/README.md b/README.md
index 8ca973e1..9e46c236 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 4dfd718e..64c32657 100644
--- a/composer.json
+++ b/composer.json
@@ -9,6 +9,7 @@
     "version": "36",
     "require": {
         "php": "~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0",
+        "dealerdirect/phpcodesniffer-composer-installer": "^0.7.2 || ^1.0",
         "webonyx/graphql-php": "^15.0",
         "ext-simplexml": "*",
         "ext-dom": "*",
@@ -35,13 +36,9 @@
             "Magento2Framework\\": "Magento2Framework/"
         }
     },
-    "scripts": {
-        "post-install-cmd": "vendor/bin/phpcs --config-set installed_paths ../../..,../../magento/php-compatibility-fork/PHPCompatibility",
-        "post-update-cmd": "vendor/bin/phpcs --config-set installed_paths ../../..,../../magento/php-compatibility-fork/PHPCompatibility"
-    },
     "config": {
         "allow-plugins": {
-            "dealerdirect/phpcodesniffer-composer-installer": false
+            "dealerdirect/phpcodesniffer-composer-installer": true
         }
     }
 }
diff --git a/composer.lock b/composer.lock
index 0059d92b..058594f3 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,7 +4,7 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "This file is @generated automatically"
     ],
-    "content-hash": "deba7764572db661a95a09a1b2e6708b",
+    "content-hash": "135692d26be282593f26e2bc99b26513",
     "packages": [
         {
             "name": "dealerdirect/phpcodesniffer-composer-installer",
@@ -2321,7 +2321,7 @@
     ],
     "aliases": [],
     "minimum-stability": "stable",
-    "stability-flags": {},
+    "stability-flags": [],
     "prefer-stable": false,
     "prefer-lowest": false,
     "platform": {
@@ -2329,6 +2329,6 @@
         "ext-simplexml": "*",
         "ext-dom": "*"
     },
-    "platform-dev": {},
+    "platform-dev": [],
     "plugin-api-version": "2.6.0"
 }