|
1 | 1 | <!-- markdownlint-disable MD041 --> |
2 | 2 | <p align="center"> |
3 | | - <picture> |
4 | | - <source media="(prefers-color-scheme: dark)" srcset="https://www.yiiframework.com/image/design/logo/yii3_full_for_dark.svg"> |
5 | | - <source media="(prefers-color-scheme: light)" srcset="https://www.yiiframework.com/image/design/logo/yii3_full_for_light.svg"> |
6 | | - <img src="https://www.yiiframework.com/image/design/logo/yii3_full_for_dark.svg" alt="Yii Framework" width="80%"> |
7 | | - </picture> |
8 | | - <h1 align="center">Template</h1> |
| 3 | + <a href="https://github.com/php-forge/coding-standard" target="_blank"> |
| 4 | + <img src="https://avatars.githubusercontent.com/u/103309199?s%25253D400%252526u%25253Dca3561c692f53ed7eb290d3bb226a2828741606f%252526v%25253D4" height="150px" alt="PHP Forge"> |
| 5 | + </a> |
| 6 | + <h1 align="center">Coding standard</h1> |
9 | 7 | <br> |
10 | 8 | </p> |
11 | 9 | <!-- markdownlint-enable MD041 --> |
12 | 10 |
|
13 | 11 | <p align="center"> |
14 | | - <a href="https://github.com/yii2-extensions/template/actions/workflows/build.yml" target="_blank"> |
15 | | - <img src="https://img.shields.io/github/actions/workflow/status/yii2-extensions/template/build.yml?style=for-the-badge&label=PHPUnit&logo=github" alt="PHPUnit"> |
16 | | - </a> |
17 | | - <a href="https://dashboard.stryker-mutator.io/reports/github.com/yii2-extensions/template/main" target="_blank"> |
18 | | - <img src="https://img.shields.io/endpoint?style=for-the-badge&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fyii2-extensions%2Ftemplate%2Fmain" alt="Mutation Testing"> |
19 | | - </a> |
20 | | - <a href="https://github.com/yii2-extensions/template/actions/workflows/static.yml" target="_blank"> |
21 | | - <img src="https://img.shields.io/github/actions/workflow/status/yii2-extensions/template/static.yml?style=for-the-badge&label=PHPStan&logo=github" alt="PHPStan"> |
| 12 | + <a href="https://github.com/php-forge/coding-standard/actions/workflows/linter.yml" target="_blank"> |
| 13 | + <img src="https://img.shields.io/github/actions/workflow/status/php-forge/coding-standard/linter.yml?style=for-the-badge&label=Super-Linter&logo=github" alt="Super-Linter"> |
22 | 14 | </a> |
23 | 15 | </p> |
24 | 16 |
|
25 | 17 | <p align="center"> |
26 | | - <strong>A Yii2 extension template to create your own Yii2 extensions</strong><br> |
27 | | - <em>PHPUnit, PHPStan, Codeception, and best practices ready out of the box</em> |
| 18 | + <strong>Centralized ECS and Rector configuration for PHP projects</strong><br> |
| 19 | + <em>Share one set of rules across multiple repositories via Composer.</em> |
28 | 20 | </p> |
29 | 21 |
|
30 | 22 | ## Features |
|
34 | 26 | <img src="./docs/svgs/features-mobile.svg" alt="Feature Overview" style="width: 100%;"> |
35 | 27 | </picture> |
36 | 28 |
|
| 29 | +## Installation |
| 30 | + |
| 31 | +```bash |
| 32 | +composer require php-forge/coding-standard:^0.1 --dev |
| 33 | +``` |
| 34 | + |
37 | 35 | ## Quick start |
38 | 36 |
|
39 | | -### Installation |
| 37 | +This package provides shared configuration files under `vendor/php-forge/coding-standard/config/`: |
40 | 38 |
|
41 | | -```bash |
42 | | -composer require github_username/github_repository-name |
| 39 | +- `config/ecs.php` (shared ECS rules, no paths) |
| 40 | +- `config/rector.php` (shared Rector rules, no paths) |
| 41 | + |
| 42 | +Consumer repositories should create wrapper config files at the repository root. |
| 43 | +Wrappers define the paths for that repository and import the shared configuration. |
| 44 | + |
| 45 | +### Generic repository |
| 46 | + |
| 47 | +#### ECS (ecs.php) |
| 48 | + |
| 49 | +Create `ecs.php` in your repository root: |
| 50 | + |
| 51 | +```php |
| 52 | +<?php |
| 53 | + |
| 54 | +declare(strict_types=1); |
| 55 | + |
| 56 | +/** @var \Symplify\EasyCodingStandard\Configuration\ECSConfigBuilder $ecsConfigBuilder */ |
| 57 | +$ecsConfigBuilder = require __DIR__ . '/vendor/php-forge/coding-standard/config/ecs.php'; |
| 58 | + |
| 59 | +return $ecsConfigBuilder->withPaths( |
| 60 | + [ |
| 61 | + __DIR__ . '/src', |
| 62 | + __DIR__ . '/tests', |
| 63 | + ], |
| 64 | +); |
43 | 65 | ``` |
44 | 66 |
|
45 | | -### Basic Usage |
| 67 | +To override or skip rules locally, apply changes after requiring the shared config: |
46 | 68 |
|
47 | | -Describe how to use your extension in a basic way. |
| 69 | +```php |
| 70 | +<?php |
48 | 71 |
|
49 | | -## Documentation |
| 72 | +declare(strict_types=1); |
50 | 73 |
|
51 | | -For detailed configuration options and advanced usage. |
| 74 | +/** @var \Symplify\EasyCodingStandard\Configuration\ECSConfigBuilder $ecsConfigBuilder */ |
| 75 | +$ecsConfigBuilder = require __DIR__ . '/vendor/php-forge/coding-standard/config/ecs.php'; |
52 | 76 |
|
53 | | -- 📚 [Installation Guide](docs/installation.md) |
54 | | -- ⚙️ [Configuration Reference](docs/configuration.md) |
55 | | -- 💡 [Usage Examples](docs/examples.md) |
56 | | -- 🧪 [Testing Guide](docs/testing.md) |
57 | | -- 🛠️ [Development Guide](docs/development.md) |
| 77 | +return $ecsConfigBuilder |
| 78 | + ->withPaths( |
| 79 | + [ |
| 80 | + __DIR__ . '/src', |
| 81 | + __DIR__ . '/tests', |
| 82 | + ], |
| 83 | + ) |
| 84 | + ->withSkip( |
| 85 | + [ |
| 86 | + // add project-specific skips here. |
| 87 | + ], |
| 88 | + ); |
| 89 | +``` |
58 | 90 |
|
59 | | -## Package information |
| 91 | +#### Rector (rector.php) |
60 | 92 |
|
61 | | -[](https://www.php.net/releases/8.1/en.php) |
62 | | -[](https://github.com/yiisoft/yii2/tree/2.0.53) |
63 | | -[](https://github.com/yiisoft/yii2/tree/22.0) |
64 | | -[](https://packagist.org/packages/yii2-extensions/template) |
65 | | -[](https://packagist.org/packages/yii2-extensions/template) |
| 93 | +Create `rector.php` in your repository root: |
| 94 | + |
| 95 | +```php |
| 96 | +<?php |
| 97 | + |
| 98 | +declare(strict_types=1); |
66 | 99 |
|
67 | | -## Quality code |
| 100 | +use Rector\Config\RectorConfig; |
68 | 101 |
|
69 | | -[](https://codecov.io/github/yii2-extensions/template) |
70 | | -[](https://github.com/yii2-extensions/template/actions/workflows/static.yml) |
71 | | -[](https://github.com/yii2-extensions/template/actions/workflows/linter.yml) |
72 | | -[](https://github.styleci.io/repos/698621511?branch=main) |
| 102 | +return static function (RectorConfig $rectorConfig): void { |
| 103 | + $rectorConfig->import(__DIR__ . '/vendor/php-forge/coding-standard/config/rector.php'); |
73 | 104 |
|
74 | | -## Our social networks |
| 105 | + $rectorConfig->paths( |
| 106 | + [ |
| 107 | + __DIR__ . '/src', |
| 108 | + __DIR__ . '/tests', |
| 109 | + ], |
| 110 | + ); |
75 | 111 |
|
76 | | -[](https://x.com/Terabytesoftw) |
| 112 | + // project-specific overrides can be added after the import. |
| 113 | + // $rectorConfig->skip([...]); |
| 114 | +}; |
| 115 | +``` |
| 116 | + |
| 117 | +### Yii2 repositories |
| 118 | + |
| 119 | +If you need framework-specific rules (Yii2), keep them in a separate config file (or a separate package) |
| 120 | +and import it after the base configuration. Do not mix Yii2-specific rules into the generic base. |
| 121 | + |
| 122 | +Example (Rector): |
| 123 | + |
| 124 | +```php |
| 125 | +<?php |
| 126 | + |
| 127 | +declare(strict_types=1); |
| 128 | + |
| 129 | +use Rector\Config\RectorConfig; |
| 130 | + |
| 131 | +return static function (RectorConfig $rectorConfig): void { |
| 132 | + $rectorConfig->import(__DIR__ . '/vendor/php-forge/coding-standard/config/rector.php'); |
| 133 | + $rectorConfig->import(__DIR__ . '/rector-yii2.php'); |
| 134 | + |
| 135 | + $rectorConfig->paths( |
| 136 | + [ |
| 137 | + __DIR__ . '/src', |
| 138 | + __DIR__ . '/tests', |
| 139 | + ], |
| 140 | + ); |
| 141 | +}; |
| 142 | +``` |
| 143 | + |
| 144 | +## Composer scripts |
| 145 | + |
| 146 | +Follow the same convention used across PHP Forge repositories: |
| 147 | + |
| 148 | +```json |
| 149 | +{ |
| 150 | + "scripts": { |
| 151 | + "ecs": "./vendor/bin/ecs --fix", |
| 152 | + "rector": "./vendor/bin/rector process" |
| 153 | + } |
| 154 | +} |
| 155 | +``` |
| 156 | + |
| 157 | +## Documentation |
| 158 | + |
| 159 | +- [Testing Guide](docs/testing.md) |
| 160 | +- [Development Guide](docs/development.md) |
| 161 | + |
| 162 | +## Package information |
| 163 | + |
| 164 | +[](https://www.php.net/releases/8.1/en.php) |
| 165 | +[](https://packagist.org/packages/php-forge/coding-standard) |
| 166 | +[](https://packagist.org/packages/php-forge/coding-standard) |
77 | 167 |
|
78 | 168 | ## License |
79 | 169 |
|
|
0 commit comments