|
5 | 5 | use PhpCsFixer\Config; |
6 | 6 | use PhpCsFixer\Finder; |
7 | 7 |
|
| 8 | +// Scan src/tests for PHP files, exclude vendor/build/node_modules |
8 | 9 | $finder = Finder::create() |
9 | 10 | ->in([__DIR__ . '/src', __DIR__ . '/tests']) |
10 | 11 | ->name('*.php') |
11 | | - ->exclude(['vendor', 'build']) |
| 12 | + ->exclude(['vendor', 'build', 'node_modules']) |
12 | 13 | ->ignoreDotFiles(true) |
13 | 14 | ->ignoreVCS(true); |
14 | 15 |
|
|
18 | 19 | ->setCacheFile(__DIR__ . '/.php-cs-fixer.cache') |
19 | 20 | ->setFinder($finder) |
20 | 21 | ->setRules([ |
| 22 | + // =================================== |
| 23 | + // Base rules / PSR12 / PHP84 migration |
| 24 | + // =================================== |
21 | 25 | '@PSR12' => true, |
| 26 | + 'phpdoc_types' => ['groups' => []], // optional, keeps types short |
22 | 27 | '@PHP84Migration' => true, |
23 | 28 | '@DoctrineAnnotation' => true, |
24 | 29 |
|
|
30 | 35 | // Imports |
31 | 36 | 'ordered_imports' => ['sort_algorithm' => 'alpha'], |
32 | 37 | 'no_unused_imports' => true, |
33 | | - 'global_namespace_import' => [ |
34 | | - 'import_constants' => true, |
35 | | - 'import_functions' => true, |
36 | | - 'import_classes' => true, |
37 | | - ], |
38 | 38 |
|
39 | | - // Arrays & Lists |
| 39 | + // Arrays & lists |
40 | 40 | 'array_syntax' => ['syntax' => 'short'], |
41 | 41 | 'list_syntax' => ['syntax' => 'short'], |
42 | 42 | 'trim_array_spaces' => true, |
43 | 43 | 'no_whitespace_before_comma_in_array' => true, |
44 | 44 | 'whitespace_after_comma_in_array' => true, |
45 | | - 'no_trailing_comma_in_singleline_array' => true, // aligns with PSR12 |
46 | | - |
47 | | - // Functions |
| 45 | + 'no_trailing_comma_in_singleline_array' => true, |
| 46 | + 'trailing_comma_in_multiline' => true, |
48 | 47 | 'nullable_type_declaration_for_default_null_value' => true, |
49 | 48 | 'no_unreachable_default_argument_value' => true, |
50 | | - 'native_function_invocation' => [ |
51 | | - 'include' => ['@compiler_optimized'], |
52 | | - 'scope' => 'all' |
53 | | - ], |
54 | 49 | 'return_type_declaration' => ['space_before' => 'none'], |
55 | 50 |
|
56 | | - // Classes |
57 | | - 'class_attributes_separation' => ['elements' => ['method' => 'one']], |
| 51 | + // Classes & methods |
| 52 | + 'class_attributes_separation' => ['elements' => ['method' => 'one']], // one blank line between methods |
58 | 53 | 'visibility_required' => ['elements' => ['property', 'method', 'const']], |
59 | | - 'self_accessor' => false, |
| 54 | + 'self_accessor' => true, |
60 | 55 | 'no_null_property_initialization' => true, |
61 | 56 |
|
62 | 57 | // Operators & spacing |
63 | 58 | 'concat_space' => ['spacing' => 'one'], |
64 | 59 | 'binary_operator_spaces' => [ |
65 | 60 | 'default' => 'single_space', |
66 | | - 'operators' => [ |
67 | | - '=' => 'align_single_space_minimal', |
68 | | - '=>' => 'align_single_space_minimal', |
69 | | - ], |
| 61 | + 'operators' => ['='=>'align_single_space_minimal','=>'=>'align_single_space_minimal'] |
70 | 62 | ], |
71 | 63 | 'ternary_operator_spaces' => true, |
72 | 64 |
|
73 | 65 | // Strings |
74 | 66 | 'single_quote' => true, |
75 | | - 'escape_implicit_backslashes' => true, |
76 | | - 'string_implicit_backslashes' => ['single_quoted' => 'ignore'], |
77 | 67 |
|
78 | | - // Comments & Docs |
79 | | - 'phpdoc_align' => ['align' => 'left'], |
80 | | - 'phpdoc_to_comment' => false, |
81 | | - 'phpdoc_trim_consecutive_blank_line_separation' => true, |
82 | | - 'phpdoc_summary' => false, |
| 68 | + // =================================== |
| 69 | + // PHPDoc / Docblock alignment |
| 70 | + // =================================== |
| 71 | + // 'phpdoc_align' => ['align' => 'vertical'], // aligns all @param/@return |
| 72 | + // 'phpdoc_order' => true, // sort tags: param → return → throws |
| 73 | + // 'phpdoc_trim' => true, // remove extra spaces |
| 74 | + 'phpdoc_no_empty_return' => false, // remove @return void |
| 75 | + 'phpdoc_var_without_name' => true, // allow @var type without variable |
| 76 | + 'phpdoc_add_missing_param_annotation' => true, // adds missing @param |
| 77 | + 'phpdoc_scalar' => true, // use scalar types in docblocks |
| 78 | + 'phpdoc_separation' => false, // enforce no blank lines between annotations |
| 79 | + 'no_superfluous_phpdoc_tags' => ['allow_mixed' => true], // allow mixed when required |
| 80 | + // 'no_blank_lines_before_namespace' => true, // ensures file doc is at top |
83 | 81 |
|
84 | | - // Misc |
85 | | - 'no_superfluous_phpdoc_tags' => ['allow_mixed' => true], |
86 | | - 'fully_qualified_strict_types' => true, |
| 82 | + // Misc spacing & braces |
| 83 | + 'no_extra_blank_lines' => ['tokens' => ['extra','curly_brace_block','square_brace_block','parenthesis_brace_block','throw','use','return']], |
| 84 | + 'braces' => ['allow_single_line_closure' => true,'position_after_functions_and_oop_constructs' => 'same'], |
87 | 85 | ]); |
0 commit comments