Skip to content

Commit bebf3f4

Browse files
authored
Merge pull request #9035 from paulbalandan/dry-cs
chore: make php-cs-fixer configs DRY
2 parents 517aa33 + b679711 commit bebf3f4

File tree

4 files changed

+28
-71
lines changed

4 files changed

+28
-71
lines changed

.php-cs-fixer.dist.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828
'ThirdParty',
2929
'Validation/Views',
3030
])
31-
->notPath([
32-
])
3331
->notName('#Foobar.php$#')
3432
->append([
3533
__FILE__,
@@ -41,12 +39,7 @@
4139
__DIR__ . '/spark',
4240
]);
4341

44-
$overrides = [
45-
// for updating to coding-standard
46-
'modernize_strpos' => true,
47-
'ordered_attributes' => ['order' => [], 'sort_algorithm' => 'alpha'],
48-
'php_unit_attributes' => true,
49-
];
42+
$overrides = [];
5043

5144
$options = [
5245
'cacheFile' => 'build/.php-cs-fixer.cache',

.php-cs-fixer.no-header.php

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
* the LICENSE file that was distributed with this source code.
1212
*/
1313

14-
use CodeIgniter\CodingStandard\CodeIgniter4;
15-
use Nexus\CsConfig\Factory;
16-
use Nexus\CsConfig\Fixer\Comment\NoCodeSeparatorCommentFixer;
17-
use Nexus\CsConfig\FixerGenerator;
14+
use PhpCsFixer\ConfigInterface;
1815
use PhpCsFixer\Finder;
1916

17+
/** @var ConfigInterface $config */
18+
$config = require __DIR__ . '/.php-cs-fixer.dist.php';
19+
2020
$finder = Finder::create()
2121
->files()
2222
->in([
@@ -30,19 +30,10 @@
3030
]);
3131

3232
$overrides = [
33-
// for updating to coding-standard
34-
'modernize_strpos' => true,
35-
'ordered_attributes' => ['order' => [], 'sort_algorithm' => 'alpha'],
36-
'php_unit_attributes' => true,
37-
];
38-
39-
$options = [
40-
'cacheFile' => 'build/.php-cs-fixer.no-header.cache',
41-
'finder' => $finder,
42-
'customFixers' => FixerGenerator::create('vendor/nexusphp/cs-config/src/Fixer', 'Nexus\\CsConfig\\Fixer'),
43-
'customRules' => [
44-
NoCodeSeparatorCommentFixer::name() => true,
45-
],
33+
'header_comment' => false,
4634
];
4735

48-
return Factory::create(new CodeIgniter4(), $overrides, $options)->forProjects();
36+
return $config
37+
->setFinder($finder)
38+
->setCacheFile('build/.php-cs-fixer.no-header.cache')
39+
->setRules(array_merge($config->getRules(), $overrides));

.php-cs-fixer.tests.php

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,47 +11,29 @@
1111
* the LICENSE file that was distributed with this source code.
1212
*/
1313

14-
use CodeIgniter\CodingStandard\CodeIgniter4;
15-
use Nexus\CsConfig\Factory;
16-
use Nexus\CsConfig\Fixer\Comment\NoCodeSeparatorCommentFixer;
17-
use Nexus\CsConfig\FixerGenerator;
14+
use PhpCsFixer\ConfigInterface;
1815
use PhpCsFixer\Finder;
1916

17+
/** @var ConfigInterface $config */
18+
$config = require __DIR__ . '/.php-cs-fixer.dist.php';
19+
2020
$finder = Finder::create()
2121
->files()
2222
->in([
2323
__DIR__ . '/tests',
2424
])
25-
->exclude([
26-
])
2725
->notPath([
2826
'_support/View/Cells/multiplier.php',
2927
'_support/View/Cells/colors.php',
3028
'_support/View/Cells/addition.php',
3129
])
32-
->notName('#Foobar.php$#')
33-
->append([
34-
]);
30+
->notName('#Foobar.php$#');
3531

3632
$overrides = [
3733
'void_return' => true,
38-
// for updating to coding-standard
39-
'modernize_strpos' => true,
40-
'ordered_attributes' => ['order' => [], 'sort_algorithm' => 'alpha'],
41-
'php_unit_attributes' => true,
42-
];
43-
44-
$options = [
45-
'cacheFile' => 'build/.php-cs-fixer.tests.cache',
46-
'finder' => $finder,
47-
'customFixers' => FixerGenerator::create('vendor/nexusphp/cs-config/src/Fixer', 'Nexus\\CsConfig\\Fixer'),
48-
'customRules' => [
49-
NoCodeSeparatorCommentFixer::name() => true,
50-
],
5134
];
5235

53-
return Factory::create(new CodeIgniter4(), $overrides, $options)->forLibrary(
54-
'CodeIgniter 4 framework',
55-
'CodeIgniter Foundation',
56-
'admin@codeigniter.com'
57-
);
36+
return $config
37+
->setFinder($finder)
38+
->setCacheFile('build/.php-cs-fixer.tests.cache')
39+
->setRules(array_merge($config->getRules(), $overrides));

.php-cs-fixer.user-guide.php

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
* the LICENSE file that was distributed with this source code.
1212
*/
1313

14-
use CodeIgniter\CodingStandard\CodeIgniter4;
15-
use Nexus\CsConfig\Factory;
16-
use Nexus\CsConfig\Fixer\Comment\NoCodeSeparatorCommentFixer;
17-
use Nexus\CsConfig\FixerGenerator;
14+
use PhpCsFixer\ConfigInterface;
1815
use PhpCsFixer\Finder;
1916

17+
/** @var ConfigInterface $config */
18+
$config = require __DIR__ . '/.php-cs-fixer.dist.php';
19+
2020
$finder = Finder::create()
2121
->files()
2222
->in([
@@ -32,26 +32,17 @@
3232

3333
$overrides = [
3434
'echo_tag_syntax' => false,
35+
'header_comment' => false,
3536
'php_unit_internal_class' => false,
3637
'no_unused_imports' => false,
3738
'class_attributes_separation' => false,
3839
'fully_qualified_strict_types' => [
3940
'import_symbols' => false,
4041
'leading_backslash_in_global_namespace' => true,
4142
],
42-
// for updating to coding-standard
43-
'modernize_strpos' => true,
44-
'ordered_attributes' => ['order' => [], 'sort_algorithm' => 'alpha'],
45-
'php_unit_attributes' => true,
46-
];
47-
48-
$options = [
49-
'cacheFile' => 'build/.php-cs-fixer.user-guide.cache',
50-
'finder' => $finder,
51-
'customFixers' => FixerGenerator::create('vendor/nexusphp/cs-config/src/Fixer', 'Nexus\\CsConfig\\Fixer'),
52-
'customRules' => [
53-
NoCodeSeparatorCommentFixer::name() => true,
54-
],
5543
];
5644

57-
return Factory::create(new CodeIgniter4(), $overrides, $options)->forProjects();
45+
return $config
46+
->setFinder($finder)
47+
->setCacheFile('build/.php-cs-fixer.user-guide.cache')
48+
->setRules(array_merge($config->getRules(), $overrides));

0 commit comments

Comments
 (0)