https://github.com/craftcms/ecs
Easy Coding Standard configurations for Craft CMS projects.
https://github.com/craftcms/ecs
Last synced: 10 months ago
JSON representation
Easy Coding Standard configurations for Craft CMS projects.
- Host: GitHub
- URL: https://github.com/craftcms/ecs
- Owner: craftcms
- License: mit
- Created: 2022-03-05T20:57:19.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-08-07T21:54:46.000Z (almost 2 years ago)
- Last Synced: 2025-07-13T07:28:40.372Z (12 months ago)
- Language: PHP
- Homepage:
- Size: 26.4 KB
- Stars: 17
- Watchers: 4
- Forks: 5
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Easy Coding Standard config for Craft CMS
This package provides [Easy Coding Standard](https://github.com/symplify/easy-coding-standard) configurations for Craft CMS plugins and projects.
In general, we follow the [PSR-12](https://www.php-fig.org/psr/psr-12/) coding style guide, with a couple alterations:
- Multi-line function argument rules aren’t enforced. ([¶4.4](https://www.php-fig.org/psr/psr-12/#44-methods-and-functions))
- Spaces after the `function` keyword aren’t enforced. ([¶7](https://www.php-fig.org/psr/psr-12/#7-closures))
- Visibility is not enforced for constants, for Craft 3 projects.
To install, run the following commands within your plugin or project:
```sh
composer config minimum-stability dev
```
```sh
composer config prefer-stable true
```
```sh
composer require craftcms/ecs:dev-main --dev
```
Then add an `ecs.php` file to the root of your plugin or project:
```php
parallel();
$ecsConfig->paths([
__DIR__ . '/src',
__FILE__,
]);
$ecsConfig->sets([SetList::CRAFT_CMS_3]); // for Craft 3 projects
$ecsConfig->sets([SetList::CRAFT_CMS_4]); // for Craft 4 projects
};
```
Adjust the `PATHS` value to include all source/test code locations, and remove the appropriate `SetList` option,
depending on whether this is for Craft 3 or Craft 4.
With that in place, you can check your plugin/project’s code with the following command:
```sh
vendor/bin/ecs check
```
And to automatically fix it as well, pass the `--fix` argument:
```sh
vendor/bin/ecs check --fix
```
You might also want to define `check-cs` and `fix-cs` scripts in `composer.json`:
```json
{
"...": "...",
"scripts": {
"check-cs": "ecs check --ansi",
"fix-cs": "ecs check --ansi --fix"
}
}
```
Then you could execute ECS using `composer run-script`:
```sh
composer run-script check-cs
composer run-script fix-cs
```