Skip to content

Commit 98c1e48

Browse files
authored
Merge pull request #19 from php-fast-forward/feature/6-make-ecs-php-extensible
[feature] Make ecs.php extensible instead of fully replaceable
2 parents 39d3384 + cf1b370 commit 98c1e48

File tree

4 files changed

+130
-38
lines changed

4 files changed

+130
-38
lines changed

docs/configuration/overriding-defaults.rst

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,31 @@ To customize Rector for one library, create ``rector.php`` in the consumer
5151
project root. The ``refactor`` command and the Rector phase inside ``phpdoc``
5252
will use that file instead of the packaged default.
5353

54+
Extending ECS Configuration
55+
----------------------------
56+
57+
Instead of copying the entire ``ecs.php`` file, consumers can extend the
58+
default configuration using the ``ECSConfig`` class:
59+
60+
.. code-block:: php
61+
62+
<?php
63+
64+
use FastForward\DevTools\Config\ECSConfig;
65+
use PhpCsFixer\Fixer\Phpdoc\PhpdocAlignFixer;
66+
67+
$config = ECSConfig::configure();
68+
$config->withRules([CustomRule::class]);
69+
$config->withConfiguredRule(PhpdocAlignFixer::class, ['align' => 'right']);
70+
71+
return $config;
72+
73+
This approach:
74+
75+
- Eliminates duplication of the base configuration
76+
- Automatically receives upstream updates
77+
- Only requires overriding what is needed
78+
5479
What Is Not Overwritten Automatically
5580
-------------------------------------
5681

docs/faq.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,24 @@ Create only the local configuration file you want to customize, such as
7676
``rector.php`` or ``phpunit.xml``. DevTools will prefer that file and keep the
7777
rest on the packaged defaults.
7878

79+
How do I extend the ECS configuration without copying the whole file?
80+
----------------------------------------------------------------------
81+
82+
Use the ``ECSConfig`` class to extend instead of replace:
83+
84+
.. code-block:: php
85+
86+
<?php
87+
88+
use FastForward\DevTools\Config\ECSConfig;
89+
90+
$config = ECSConfig::configure();
91+
$config->withRules([CustomRule::class]);
92+
93+
return $config;
94+
95+
This approach automatically receives upstream updates while allowing additive customization.
96+
7997
Can I generate coverage without running the full ``standards`` pipeline?
8098
------------------------------------------------------------------------
8199

ecs.php

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -16,42 +16,6 @@
1616
* @see https://datatracker.ietf.org/doc/html/rfc2119
1717
*/
1818

19-
use PhpCsFixer\Fixer\Import\GlobalNamespaceImportFixer;
20-
use PhpCsFixer\Fixer\Phpdoc\GeneralPhpdocAnnotationRemoveFixer;
21-
use PhpCsFixer\Fixer\Phpdoc\PhpdocAlignFixer;
22-
use PhpCsFixer\Fixer\Phpdoc\NoEmptyPhpdocFixer;
23-
use PhpCsFixer\Fixer\Phpdoc\NoSuperfluousPhpdocTagsFixer;
24-
use PhpCsFixer\Fixer\Phpdoc\PhpdocAddMissingParamAnnotationFixer;
25-
use PhpCsFixer\Fixer\Phpdoc\PhpdocNoEmptyReturnFixer;
26-
use PhpCsFixer\Fixer\Phpdoc\PhpdocToCommentFixer;
27-
use PhpCsFixer\Fixer\PhpUnit\PhpUnitTestCaseStaticMethodCallsFixer;
28-
use Symplify\EasyCodingStandard\Config\ECSConfig;
19+
use FastForward\DevTools\Config\ECSConfig;
2920

30-
use function Safe\getcwd;
31-
32-
return ECSConfig::configure()
33-
->withPaths([getcwd()])
34-
->withSkip([
35-
getcwd() . '/public',
36-
getcwd() . '/resources',
37-
getcwd() . '/vendor',
38-
getcwd() . '/tmp',
39-
PhpdocToCommentFixer::class,
40-
NoSuperfluousPhpdocTagsFixer::class,
41-
NoEmptyPhpdocFixer::class,
42-
PhpdocNoEmptyReturnFixer::class,
43-
GlobalNamespaceImportFixer::class,
44-
GeneralPhpdocAnnotationRemoveFixer::class,
45-
])
46-
->withRootFiles()
47-
->withPhpCsFixerSets(symfony: true, symfonyRisky: true, auto: true, autoRisky: true)
48-
->withPreparedSets(psr12: true, common: true, symplify: true, strict: true, cleanCode: true)
49-
->withConfiguredRule(PhpdocAlignFixer::class, [
50-
'align' => 'left',
51-
])
52-
->withConfiguredRule(PhpUnitTestCaseStaticMethodCallsFixer::class, [
53-
'call_type' => 'self',
54-
])
55-
->withConfiguredRule(PhpdocAddMissingParamAnnotationFixer::class, [
56-
'only_untyped' => false,
57-
]);
21+
return ECSConfig::configure();

src/Config/ECSConfig.php

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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

Comments
 (0)