-
Notifications
You must be signed in to change notification settings - Fork 1
Add PHP-CS-Fixer Config and Rules classes #30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
c1257da
b5df108
b57ba26
2f2db2a
e5d43ab
9732cd6
9e1ced9
fa63771
d757a33
76019f2
bac37cd
aa40b19
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| <?php declare(strict_types=1); | ||
|
|
||
| namespace IxDFCodingStandard\PhpCsFixer; | ||
|
|
||
| use PhpCsFixer\Config as BaseConfig; | ||
| use PhpCsFixer\Finder; | ||
| use PhpCsFixer\Runner\Parallel\ParallelConfigFactory; | ||
|
|
||
| /** | ||
| * Pre-configured PHP-CS-Fixer config factory for IxDF projects. | ||
| * @see README.md for usage examples | ||
| */ | ||
| final class Config | ||
| { | ||
| // 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); | ||
|
Comment on lines
+15
to
+29
|
||
| } | ||
|
|
||
| private static function defaultFinder(string $projectDir): Finder | ||
| { | ||
| return Finder::create() | ||
| ->in($projectDir) | ||
| ->exclude([ | ||
| '.cache', | ||
| '.docker', | ||
| 'bootstrap/cache', | ||
| 'node_modules', | ||
| 'public', | ||
| 'storage', | ||
| 'vendor', | ||
| ]) | ||
| ->name('*.php') | ||
| ->notName('*.blade.php') | ||
| ->notName('_ide_helper.php') | ||
| ->notName('.phpstorm.meta.php') | ||
| ->ignoreDotFiles(false) | ||
| ->ignoreVCS(true) | ||
| ->ignoreVCSIgnored(true); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| <?php declare(strict_types=1); | ||
|
|
||
| namespace IxDFCodingStandard\PhpCsFixer; | ||
|
|
||
| /** | ||
| * Shared PHP-CS-Fixer rules for IxDF projects. | ||
| * @see https://mlocati.github.io/php-cs-fixer-configurator/ | ||
| */ | ||
| final class Rules | ||
| { | ||
| // phpcs:ignore SlevomatCodingStandard.TypeHints.DisallowMixedTypeHint.DisallowedMixedTypeHint | ||
| /** @var array<string, array<string, mixed>|bool>|null */ | ||
| private static ?array $rules = null; | ||
|
|
||
| // phpcs:ignore SlevomatCodingStandard.TypeHints.DisallowMixedTypeHint.DisallowedMixedTypeHint | ||
| /** @return array<string, array<string, mixed>|bool> */ | ||
| public static function get(): array | ||
| { | ||
|
Comment on lines
+14
to
+18
|
||
| return self::$rules ??= require dirname(__DIR__, 2).'/.php-cs-fixer-rules.php'; | ||
| } | ||
| } | ||
There was a problem hiding this comment.
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 toIxDFCodingStandard\PhpCsFixer\Config/Rules::get()).