Skip to content

Commit

Permalink
Use a composer plugin to register the standard
Browse files Browse the repository at this point in the history
  • Loading branch information
fredden committed Feb 1, 2023
1 parent 1172711 commit a2cb670
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 20 deletions.
16 changes: 1 addition & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
```
Expand Down
8 changes: 5 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "*",
Expand All @@ -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
}
}
}
82 changes: 80 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a2cb670

Please sign in to comment.