|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +/** |
| 6 | + * This file is part of fast-forward/dev-tools. |
| 7 | + * |
| 8 | + * This source file is subject to the license bundled |
| 9 | + * with this source code in the file LICENSE. |
| 10 | + * |
| 11 | + * @copyright Copyright (c) 2026 Felipe Sayão Lobato Abreu <github@mentordosnerds.com> |
| 12 | + * @license https://opensource.org/licenses/MIT MIT License |
| 13 | + * |
| 14 | + * @see https://github.com/php-fast-forward/dev-tools |
| 15 | + * @see https://github.com/php-fast-forward |
| 16 | + * @see https://datatracker.ietf.org/doc/html/rfc2119 |
| 17 | + */ |
| 18 | + |
| 19 | +namespace FastForward\DevTools\Config; |
| 20 | + |
| 21 | +use PhpCsFixer\Fixer\Import\GlobalNamespaceImportFixer; |
| 22 | +use PhpCsFixer\Fixer\Phpdoc\GeneralPhpdocAnnotationRemoveFixer; |
| 23 | +use PhpCsFixer\Fixer\Phpdoc\PhpdocAlignFixer; |
| 24 | +use PhpCsFixer\Fixer\Phpdoc\NoEmptyPhpdocFixer; |
| 25 | +use PhpCsFixer\Fixer\Phpdoc\NoSuperfluousPhpdocTagsFixer; |
| 26 | +use PhpCsFixer\Fixer\Phpdoc\PhpdocAddMissingParamAnnotationFixer; |
| 27 | +use PhpCsFixer\Fixer\Phpdoc\PhpdocNoEmptyReturnFixer; |
| 28 | +use PhpCsFixer\Fixer\Phpdoc\PhpdocToCommentFixer; |
| 29 | +use PhpCsFixer\Fixer\PhpUnit\PhpUnitTestCaseStaticMethodCallsFixer; |
| 30 | +use Symplify\EasyCodingStandard\Configuration\ECSConfigBuilder; |
| 31 | + |
| 32 | +use function Safe\getcwd; |
| 33 | + |
| 34 | +/** |
| 35 | + * Provides the default ECS configuration. |
| 36 | + * |
| 37 | + * Consumers can use this as a starting point and extend it: |
| 38 | + * |
| 39 | + * $config = \FastForward\DevTools\Config\ECSConfig::configure(); |
| 40 | + * $config->withRules([CustomRule::class]); |
| 41 | + * $config->withConfiguredRule(PhpdocAlignFixer::class, ['align' => 'right']); |
| 42 | + * return $config; |
| 43 | + * |
| 44 | + * @see https://github.com/symplify/easy-coding-standard |
| 45 | + */ |
| 46 | +final class ECSConfig |
| 47 | +{ |
| 48 | + /** |
| 49 | + * Creates the default ECS configuration. |
| 50 | + * |
| 51 | + * @return ECSConfigBuilder the configured ECS configuration builder |
| 52 | + */ |
| 53 | + public static function configure(): ECSConfigBuilder |
| 54 | + { |
| 55 | + $cwd = getcwd(); |
| 56 | + $config = new ECSConfigBuilder(); |
| 57 | + |
| 58 | + return $config |
| 59 | + ->withPaths([$cwd]) |
| 60 | + ->withSkip([ |
| 61 | + $cwd . '/public', |
| 62 | + $cwd . '/resources', |
| 63 | + $cwd . '/vendor', |
| 64 | + $cwd . '/tmp', |
| 65 | + PhpdocToCommentFixer::class, |
| 66 | + NoSuperfluousPhpdocTagsFixer::class, |
| 67 | + NoEmptyPhpdocFixer::class, |
| 68 | + PhpdocNoEmptyReturnFixer::class, |
| 69 | + GlobalNamespaceImportFixer::class, |
| 70 | + GeneralPhpdocAnnotationRemoveFixer::class, |
| 71 | + ]) |
| 72 | + ->withRootFiles() |
| 73 | + ->withPhpCsFixerSets(symfony: true, symfonyRisky: true, auto: true, autoRisky: true) |
| 74 | + ->withPreparedSets(psr12: true, common: true, symplify: true, strict: true, cleanCode: true) |
| 75 | + ->withConfiguredRule(PhpdocAlignFixer::class, [ |
| 76 | + 'align' => 'left', |
| 77 | + ]) |
| 78 | + ->withConfiguredRule(PhpUnitTestCaseStaticMethodCallsFixer::class, [ |
| 79 | + 'call_type' => 'self', |
| 80 | + ]) |
| 81 | + ->withConfiguredRule(PhpdocAddMissingParamAnnotationFixer::class, [ |
| 82 | + 'only_untyped' => false, |
| 83 | + ]); |
| 84 | + } |
| 85 | +} |
0 commit comments