-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphp_cs.php
More file actions
134 lines (126 loc) · 4.94 KB
/
php_cs.php
File metadata and controls
134 lines (126 loc) · 4.94 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?php
declare(strict_types=1);
/**
* This is the default PHP-CS-Fixer configs for PHPQA projects.
*
* You can override this file by copying it into your qaConfig folder and editing as you see fit
*
* For rules, suggest you have a look at
*
* @see https://mlocati.github.io/php-cs-fixer-configurator/
*
* PHP 8.4 Compatibility Note:
* - This config includes PHP 8.4 migration rules via @PHP8x4Migration
* - Property hooks are not yet fully supported by PHP CS Fixer (as of 2025)
* - PHP CS Fixer v3.84.0+ supports PHP 8.4 natively (no PHP_CS_FIXER_IGNORE_ENV needed)
*/
use Composer\Autoload\ClassLoader;
use PhpCsFixer\Runner\Parallel\ParallelConfigFactory;
$rules = [
'@PhpCsFixer' => true,
'@Symfony' => true,
'@DoctrineAnnotation' => true,
'@PHP8x4Migration' => true,
'align_multiline_comment' => true,
'array_indentation' => true,
'array_syntax' => ['syntax' => 'short'],
'blank_line_after_opening_tag' => true,
'binary_operator_spaces' => [
'default' => 'align',
'operators' => [
'=>' => 'align_single_space_by_scope'
]
],
'cast_spaces' => ['space' => 'none'],
'concat_space' => ['spacing' => 'one'],
'declare_strict_types' => true,
'final_class' => true,
'ordered_class_elements' => [
'order' => [
'use_trait',
'constant_public',
'constant_protected',
'constant_private',
'property_public',
'property_protected',
'property_private',
'construct',
'destruct',
'magic',
'phpunit',
'method_public',
'method_protected',
'method_private',
],
],
// phpcs/phpcbf have been removed from the pipeline in favor of PHP CS Fixer
'ordered_imports' => [
'sort_algorithm' => 'alpha',
// this is the PSR12 order, do not change
'imports_order' => [
'class',
'function',
'const',
],
],
'modernize_types_casting' => true,
// 'php_unit_strict' => [
// 'assertions' => [
// 'assertAttribuassertionsteEquals',
// 'assertAttributeNotEquals',
// 'assertEquals',
// 'assertNotEquals',
// ],
// ],
// this one is not compatible with attributes
// 'php_unit_size_class' => ['group' => 'small'],
// this one is not compatible with attributes
'php_unit_test_class_requires_covers' => false,
'psr_autoloading' => true,
'return_assignment' => true,
'self_accessor' => true,
'static_lambda' => true,
'strict_comparison' => true,
'strict_param' => true,
'ternary_to_null_coalescing' => true,
'void_return' => true,
'yoda_style' => [
'equal' => true,
'identical' => true,
],
'fully_qualified_strict_types' => true,
'native_function_invocation' => true,
'method_argument_space' => [
'after_heredoc' => true,
'keep_multiple_spaces_after_comma' => true,
'on_multiline' => 'ensure_fully_multiline',
],
'single_line_throw' => false,
'global_namespace_import' => true,
'phpdoc_to_return_type' => false,
'no_superfluous_phpdoc_tags' => true,
'phpdoc_to_comment' => false, // otherwise we cant use @var comments to help stan understand things
// PHP 8.4 specific rules
'nullable_type_declaration_for_default_null_value' => true, // Critical for PHP 8.4 compatibility
'nullable_type_declaration' => ['syntax' => 'question_mark'], // Use ? syntax for nullable types
];
$projectRoot = (static function () {
$reflection = new ReflectionClass(ClassLoader::class);
return \dirname($reflection->getFileName(), 3);
})();
if (str_starts_with($projectRoot, 'phar')) {
// When CS Fixer runs as a PHAR, the ClassLoader reflection gives a phar:// path.
// Use getcwd() which is always the actual project root (set by the QA pipeline).
$projectRoot = getcwd();
}
$finderPath = __DIR__ . '/php_cs_finder.php';
$overridePath = "{$projectRoot}/qaConfig/php_cs_finder.php";
if (file_exists($overridePath)) {
$finderPath = $overridePath;
}
$finder = require $finderPath;
return (new PhpCsFixer\Config())
->setRules($rules)
->setFinder($finder)
->setParallelConfig(ParallelConfigFactory::detect())
;