Skip to content

Add PHP-CS-Fixer Config and Rules classes#30

Merged
alies-dev merged 12 commits intomainfrom
share-php-cs-fixer-config
Mar 6, 2026
Merged

Add PHP-CS-Fixer Config and Rules classes#30
alies-dev merged 12 commits intomainfrom
share-php-cs-fixer-config

Conversation

@alies-dev
Copy link
Member

@alies-dev alies-dev commented Mar 6, 2026

Summary

  • Added IxDFCodingStandard\PhpCsFixer\Config factory class for creating pre-configured PHP-CS-Fixer configs
  • Added IxDFCodingStandard\PhpCsFixer\Rules class that exposes shared rules via Rules::get()
  • Moved friendsofphp/php-cs-fixer from require-dev to require (needed for the public API)
  • Updated README with usage examples

Before (hacky vendor path require):

$rules = require __DIR__.'/vendor/interaction-design-foundation/coding-standard/.php-cs-fixer-rules.php';
// ...20 lines of boilerplate config...

After:

use IxDFCodingStandard\PhpCsFixer\Config;
return Config::create(__DIR__);

The old .php-cs-fixer-rules.php file is kept for backward compatibility.

alies-dev and others added 2 commits March 6, 2026 13:14
Provides a proper API for sharing php-cs-fixer config across projects,
replacing the hacky vendor path require approach.
@alies-dev alies-dev self-assigned this Mar 6, 2026
- 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.
@alies-dev alies-dev merged commit 481b8c2 into main Mar 6, 2026
7 checks passed
@alies-dev alies-dev deleted the share-php-cs-fixer-config branch March 6, 2026 13:03
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.php for backward compatibility.
  • Move friendsofphp/php-cs-fixer to require and 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.

Comment on lines +14 to +18

// phpcs:ignore SlevomatCodingStandard.TypeHints.DisallowMixedTypeHint.DisallowedMixedTypeHint
/** @return array<string, array<string, mixed>|bool> */
public static function get(): array
{
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines 44 to 50
],
'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,
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()).

Copilot uses AI. Check for mistakes.
Comment on lines +15 to +29
// 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);
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants