-
Notifications
You must be signed in to change notification settings - Fork 0
/
ecs.php
84 lines (70 loc) · 3.02 KB
/
ecs.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
declare(strict_types=1);
// composer require --dev symplify/easy-coding-standard
// symplify/easy-coding-standard
use PhpCsFixer\Fixer\ArrayNotation\ArraySyntaxFixer;
use PhpCsFixer\Fixer\Operator\BinaryOperatorSpacesFixer;
use PhpCsFixer\Fixer\Strict\DeclareStrictTypesFixer;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\EasyCodingStandard\ValueObject\Option;
use Symplify\EasyCodingStandard\ValueObject\Set\SetList;
return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
// https://tomasvotruba.com/blog/introducing-up-to-16-times-faster-easy-coding-standard/
// $parameters->set(Option::PARALLEL, true); // requires 9.4.70+
// Laravel app setup
$parameters->set(Option::PATHS, [
__DIR__ . '/app',
// __DIR__ . '/src',
__DIR__ . '/bootstrap',
__DIR__ . '/config',
__DIR__ . '/database',
__DIR__ . '/public',
__DIR__ . '/resources',
__DIR__ . '/routes',
__DIR__ . '/tests',
__DIR__ . '/ecs.php', // check this file too!
]);
$parameters->set(Option::SKIP, [
// I don't want to remove unused imports, at the beginning of the app, then the app is close to
// production these SKIP files can be removed and cleaned.
PhpCsFixer\Fixer\Import\NoUnusedImportsFixer::class,
// I can remove return types from doc blocks later, keep in for now.
PhpCsFixer\Fixer\Phpdoc\PhpdocNoEmptyReturnFixer::class,
]);
$services = $containerConfigurator->services();
$services->set(ArraySyntaxFixer::class)
->call('configure', [
[
'syntax' => 'short',
],
]);
// add declare(strict_types=1); to all php files:
$services->set(DeclareStrictTypesFixer::class);
// run and fix, one by one
$containerConfigurator->import(SetList::SPACES);
$containerConfigurator->import(SetList::ARRAY);
$containerConfigurator->import(SetList::DOCBLOCK);
$containerConfigurator->import(SetList::NAMESPACES);
$containerConfigurator->import(SetList::CONTROL_STRUCTURES);
$containerConfigurator->import(SetList::CLEAN_CODE);
$containerConfigurator->import(SetList::STRICT);
$containerConfigurator->import(SetList::PSR_12);
$containerConfigurator->import(SetList::PHPUNIT);
// align key value pairs (mostly)
$services->set(BinaryOperatorSpacesFixer::class)
->call('configure', [
[
// Likely problems are pipe operators
// if this is a problem change 'default' => 'single'
// and uncomment this lines:
'default' => 'align_single_space_minimal',
'operators' => [
'|' => 'no_space',
'=>' => 'align_single_space_minimal',
],
],
]);
$parameters->set(Option::INDENTATION, 'spaces');
$parameters->set(Option::LINE_ENDING, "\n");
};