Commit 117338e
authored
Modernize coding standard: PHP 8.4, PER-CS 3, Rector, dedup rules (#42)
* Improve PHP-CS-Fixer config sharing, require PHP 8.4, and slim PHP_CodeSniffer (#38)
* feat: improve PHP-CS-Fixer config sharing and require PHP 8.4
- Add @PHP8x4Migration, @PHP8x4Migration:risky and @PHPUnit10x0Migration:risky
rulesets for automatic syntax/test modernization, plus numeric_literal_separator.
- Mark Config and Rules as @api to declare the supported BC surface.
- Add a smoke test covering Rules::get() and Config::create().
- Fix the stale raw-require path example in the rules file docblock.
- Bump required PHP to ^8.4 and drop 8.3 from the CI matrix.
- Restructure README: PHP-CS-Fixer first, then PHP_CodeSniffer, for clarity.
* refactor: drop phpcs sniffs already covered by PHP-CS-Fixer
Now that the shared PHP-CS-Fixer config owns formatting, stop checking the
same issues with PHP_CodeSniffer (PHP-CS-Fixer is faster and auto-fixes).
Removed 30 sniffs whose concern is fully handled by an enabled fixer rule
(verified against the expanded 151-rule set), e.g. array syntax/indentation,
cast and operator spacing, trailing commas, yoda style, null coalesce,
short list, import ordering, scope indentation, superfluous whitespace.
Kept sniffs with no fixer equivalent in our config: single_quote,
native_function_casing, AND/OR operators, == vs ===, member var scope,
annotation-aware unused imports, and const/property spacing.
Generic.CodeAnalysis.EmptyStatement is kept: it detects empty control-structure
bodies, not stray semicolons (that is Slevomat UselessSemicolon, which is removed).
* refactor: drop PSR12 phpcs ref, keep only PSR1 structural sniffs
PHP-CS-Fixer's @PER-CS3x0 (PER-CS supersedes PSR-12) already enforces every
PSR12 formatting concern, verified against the expanded fixer ruleset. Replace
the whole PSR12 ref with the three PSR1 sniffs PHP-CS-Fixer cannot cover:
side-effect separation, one-symbol-per-file, and method camelCase naming.
Const visibility stays enforced via SlevomatCodingStandard.Classes.ClassConstantVisibility.
README now states PHP-CS-Fixer is primary (owns formatting) and PHP_CodeSniffer
is supplementary, not a complete standard on its own.
* fix: stop forcing arrow functions and numeric literal separators
Both came from the newly added rules and produced unwanted rewrites:
- use_arrow_functions (via @PHP8x4Migration:risky) converted readable long
closures to fn(); disable it to match the existing phpcs intent
(SlevomatCodingStandard.Functions.RequireArrowFunction is kept disabled).
- numeric_literal_separator rewrote literals like 2020 to 2_020; drop it.
* Inline shared PHP-CS-Fixer rules into the Rules class (#39)
* refactor: inline shared rules into Rules class, drop root rules file
Move the rule array from the root .php-cs-fixer-rules.php into Rules::get() so
the ruleset is a single PSR-4 autoloaded source with no file-path indirection
(dirname(__DIR__, 2) require). The raw-require fallback the root file provided
was never documented as public API, so this is safe on the unreleased 1.x line.
Also keep '@api' out of general_phpdoc_annotation_remove: the standard was
stripping the @api tags that mark the supported public surface (found by running
the shared config on this package's own code).
* chore: suppress FunctionLength on the inlined rule list
* ci: dogfood the shared PHP-CS-Fixer config on this package (#40)
Add a .php-cs-fixer.dist.php that lints this package with its own shared config,
plus a strict PHP-CS-Fixer CI gate so a config regression (e.g. a rule renamed or
removed by a dependency bump) fails loudly instead of shipping unnoticed.
- .php-cs-fixer.dist.php: uses Config::create(); excludes vendor/.cache and the
intentionally-malformed sniff test fixtures (tests/Sniffs/**); disables
mb_str_functions (this package processes ASCII PHP tokens, not user-facing
strings, so it should not pull in an ext-mbstring runtime dependency).
- composer.json: add `php-cs-fixer` and `php-cs-fixer:check` scripts.
- .github/workflows/php-cs-fixer.yml: strict dry-run gate (mirrors psalm.yml).
- Apply the resulting formatting to the package source.
- BladeTemplateExtractor: turn the `phpcs:disable` doc block into a line comment
so PHP-CS-Fixer no longer expands it into a multi-line doc block that then
conflicts with SlevomatCodingStandard.Commenting.RequireOneLineDocComment.
* feat: add `general_phpdoc_tag_rename` rule to standardize `inheritdoc` as `inheritDoc`
* feat: expand `phpdoc_line_span` rule configuration for improved control over docblock formatting
* chore: remove redundant `setCacheFile` call from PHP-CS-Fixer config
removed as too opinionated
* feat: enable `global_namespace_import` and restore `ordered_class_elements` for improved control over imports and declaration order
* chore: fix cache path and typo in README examples
* chore: install rector, apply cs to this package
* docs: reorganize for clarity
* docs: add CI workflow example with auto-fix
* ci: consolidate style workflows into one auto-fix workflow
Replace php-cs-fixer.yml (hard gate) and format_php.yml (both referenced
removed composer scripts) with a single coding-standard.yml that runs
Rector, PHP-CS-Fixer and phpcbf, then commits fixes back. `composer cs`
now chains both tools. README links to the workflow as a usage example.
* cleanup
* cleanup
* cleanup toolchain
* docs: cleanup
* style: update line length rules in cs config
* style: update line length rules in cs config
* style: adjust cognitive complexity rules in cs config
* style: adjust line length warning to 180 chars
* style: increase max function length to 70 lines in cs config
* style: exclude test files from unused variable rule
* feat: move more rules from phpcs to php-cs-fixer
* style: add report-only rules for abstract/final classes
and static closures, clarify risky rules in CS config
* style: allow mixed phpdoc tags for magic methods in CS config
* style: clarify exclusion of `no_superfluous_phpdoc_tags`
* docs: rearrange README headings for clarity1 parent 6179b0f commit 117338e
35 files changed
Lines changed: 567 additions & 614 deletions
File tree
- .github/workflows
- IxDFCodingStandard
- Helpers
- PhpCsFixer
- Sniffs
- Classes
- Files
- Functions
- Laravel
- NamingConventions
- docs
- tests
- PhpCsFixer
- Sniffs/Classes
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
This file was deleted.
File renamed without changes.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
29 | 28 | | |
30 | 29 | | |
31 | 30 | | |
| |||
This file was deleted.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
7 | | - | |
8 | | - | |
| 6 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| |||
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
25 | | - | |
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| |||
0 commit comments