|
| 1 | +# CakePHP CodeSniffer rules for Mago |
| 2 | + |
| 3 | +[](https://github.com/josbeir/cakephp-mago-rules/actions/workflows/quality.yml) |
| 4 | +[](LICENSE) |
| 5 | +[](https://packagist.org/packages/josbeir/cakephp-mago-rules) |
| 6 | +[](https://mago.carthage.software/) |
| 7 | + |
| 8 | +An upstream-ready Mago extension that targets compatibility with the CakePHP |
| 9 | +CodeSniffer standard. Mago remains the formatter; this package supplies the |
| 10 | +CakePHP-specific rules that do not have a native Mago equivalent. |
| 11 | + |
| 12 | +## Installation |
| 13 | + |
| 14 | +```sh |
| 15 | +composer require --dev josbeir/cakephp-mago-rules carthage-software/mago |
| 16 | +``` |
| 17 | + |
| 18 | +Add this to the project `mago.toml`: |
| 19 | + |
| 20 | +```toml |
| 21 | +extends = "vendor/josbeir/cakephp-mago-rules/mago.cakephp.toml" |
| 22 | +``` |
| 23 | + |
| 24 | +The imported configuration starts the package-owned worker. No copied worker |
| 25 | +or project bootstrap is required. Projects that combine several extensions in |
| 26 | +one PHP worker can still override `[extension-hosts.cakephp]` and use their |
| 27 | +own entrypoint. |
| 28 | + |
| 29 | +Run `mago extension validate` and `mago format`. For strict CakePHP |
| 30 | +compatibility, use an explicit lint allow-list: Mago's normal `lint` command |
| 31 | +also enables its broader quality and security rules, which CakePHP PHPCS does |
| 32 | +not define. |
| 33 | + |
| 34 | +```sh |
| 35 | +mago lint --only no-short-opening-tag,no-error-control-operator,no-assign-in-condition,no-redundant-parentheses,no-redundant-final,no-redundant-use,no-closing-tag,mago-cakephp/trait-suffix,mago-cakephp/public-method-underscore,mago-cakephp/elseif,mago-cakephp/function-docblock |
| 36 | +``` |
| 37 | + |
| 38 | +## What this does—and does not—replace |
| 39 | + |
| 40 | +This package is a focused CakePHP compatibility layer for Mago, not a |
| 41 | +drop-in replacement for PHP_CodeSniffer or every CakePHP CodeSniffer sniff. |
| 42 | +Its covered rules are listed in the |
| 43 | +[compatibility matrix](docs/compatibility-matrix.md); anything marked |
| 44 | +**planned** is deliberately not enforced yet. |
| 45 | + |
| 46 | +Mago is a strong fit when you want one fast PHP toolchain for formatting and |
| 47 | +linting, safe automatic fixes for supported diagnostics, and CakePHP-specific |
| 48 | +checks integrated into the same command and configuration. The package-owned |
| 49 | +worker means a consuming project only needs one `extends` entry—no copied |
| 50 | +bootstrap file or per-project rule registration. |
| 51 | + |
| 52 | +Keep PHP_CodeSniffer in place when you require complete CakePHP CodeSniffer |
| 53 | +coverage, a specific sniff's options or severity behavior, exact PHPCBF |
| 54 | +output, or checks that are still planned here (notably detailed PHPDoc rules, |
| 55 | +control-structure rules, and filename/type conventions). Run both tools during |
| 56 | +the transition if the CakePHP standard is a release gate. |
| 57 | + |
| 58 | +Formatter output is not intended to be byte-for-byte identical to PHPCBF |
| 59 | +output. Compatibility means matching the documented, supported policy—not |
| 60 | +emulating PHP_CodeSniffer internals. |
| 61 | + |
| 62 | +## Development validation |
| 63 | + |
| 64 | +Run `composer test`, `composer run validate-extension`, and |
| 65 | +`scripts/check-cakephp-5.sh`. The latter accepts an optional existing shallow |
| 66 | +CakePHP 5.x checkout, which keeps iterative checks fast: |
| 67 | + |
| 68 | +```sh |
| 69 | +scripts/check-cakephp-5.sh /tmp/cakephp-5 |
| 70 | +``` |
0 commit comments