Add PHP-CS-Fixer Config and Rules classes#30
Conversation
Provides a proper API for sharing php-cs-fixer config across projects, replacing the hacky vendor path require approach.
- blank_line_before_statement: blank lines before return, throw, try, etc. - multiline_whitespace_before_semicolons: no_multi_line strategy - no_superfluous_phpdoc_tags: remove redundant @inheritdoc - nullable_type_declaration_for_default_null_value: explicit nullability - numeric_literal_separator: 1_000_000 instead of 1000000 - ordered_imports: class, function, const order
It removes @inheritdoc which is needed by PHPStan.
These add noise in short methods where the blank line is unnecessary.
There was a problem hiding this comment.
Pull request overview
This PR adds a supported PHP-CS-Fixer integration to the coding-standard package by introducing a config factory + shared rules accessor, and documents the intended consumer usage.
Changes:
- Add
IxDFCodingStandard\PhpCsFixer\Config::create()to generate a pre-configured PHP-CS-Fixer config for a project directory. - Add
IxDFCodingStandard\PhpCsFixer\Rules::get()to expose the shared rules array, while keeping.php-cs-fixer-rules.phpfor backward compatibility. - Move
friendsofphp/php-cs-fixertorequireand update README with new usage examples.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| composer.json | Moves PHP-CS-Fixer to production requirements and updates package description. |
| README.md | Documents new recommended consumer setup for PHPCS and PHP-CS-Fixer, including composer scripts. |
| IxDFCodingStandard/PhpCsFixer/Rules.php | Introduces a stable accessor for the shared PHP-CS-Fixer rules array. |
| IxDFCodingStandard/PhpCsFixer/Config.php | Adds a factory for a standardized PHP-CS-Fixer configuration + default Finder. |
| .php-cs-fixer-rules.php | Extends the shared ruleset with a few additional fixers. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
|
|
||
| // phpcs:ignore SlevomatCodingStandard.TypeHints.DisallowMixedTypeHint.DisallowedMixedTypeHint | ||
| /** @return array<string, array<string, mixed>|bool> */ | ||
| public static function get(): array | ||
| { |
There was a problem hiding this comment.
No test coverage is introduced for this new public rules accessor. Consider adding a small PHPUnit test asserting Rules::get() returns an array and is stable across calls (e.g., same content), so changes to the rules file path/loading don’t silently break consumers.
| ], | ||
| 'modernize_types_casting' => true, | ||
| 'mb_str_functions' => true, | ||
| 'multiline_whitespace_before_semicolons' => ['strategy' => 'no_multi_line'], | ||
| 'no_alias_functions' => true, | ||
| 'no_binary_string' => true, | ||
| 'no_empty_comment' => true, |
There was a problem hiding this comment.
The header docblock in this rules file still references “PER projects” and an old vendor path (interaction-design-foundation/php-cs-fixer-rules.php). Since this file is being touched and is now effectively a supported integration point, update the header usage example/text to match the current package name/path (and/or point users to IxDFCodingStandard\PhpCsFixer\Config / Rules::get()).
| // phpcs:ignore SlevomatCodingStandard.TypeHints.DisallowMixedTypeHint.DisallowedMixedTypeHint | ||
| /** @param array<string, array<string, mixed>|bool> $ruleOverrides Rules to merge on top of the shared ruleset */ | ||
| public static function create(string $projectDir, array $ruleOverrides = [], ?Finder $finder = null): BaseConfig | ||
| { | ||
| $finder ??= self::defaultFinder($projectDir); | ||
|
|
||
| return (new BaseConfig()) | ||
| ->setParallelConfig(ParallelConfigFactory::detect()) | ||
| ->setUsingCache(true) | ||
| ->setCacheFile($projectDir.'/.cache/.php-cs-fixer.cache') | ||
| ->setRiskyAllowed(true) | ||
| ->setIndent(' ') | ||
| ->setLineEnding("\n") | ||
| ->setRules(array_merge(Rules::get(), $ruleOverrides)) | ||
| ->setFinder($finder); |
There was a problem hiding this comment.
No test coverage is introduced for this new public factory API. Adding PHPUnit tests that assert the returned config has the expected rules applied (including override precedence), sets a Finder, and uses the expected cache/parallel settings would help prevent accidental breaking changes.
Summary
IxDFCodingStandard\PhpCsFixer\Configfactory class for creating pre-configured PHP-CS-Fixer configsIxDFCodingStandard\PhpCsFixer\Rulesclass that exposes shared rules viaRules::get()friendsofphp/php-cs-fixerfromrequire-devtorequire(needed for the public API)Before (hacky vendor path require):
After:
The old
.php-cs-fixer-rules.phpfile is kept for backward compatibility.