|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace WayOfDev\PhpCsFixer\Config\RuleSets; |
| 6 | + |
| 7 | +use PhpCsFixer\Fixer\FunctionNotation\NativeFunctionInvocationFixer; |
| 8 | +use WayOfDev\PhpCsFixer\Config\RuleSet; |
| 9 | + |
| 10 | +use function array_merge; |
| 11 | + |
| 12 | +final class ExtendedPERSet implements RuleSet |
| 13 | +{ |
| 14 | + public function __construct(private readonly array $rules = []) |
| 15 | + { |
| 16 | + } |
| 17 | + |
| 18 | + public function name(): string |
| 19 | + { |
| 20 | + return 'ExtendedPER'; |
| 21 | + } |
| 22 | + |
| 23 | + public function allowRisky(): bool |
| 24 | + { |
| 25 | + return true; |
| 26 | + } |
| 27 | + |
| 28 | + public function useCache(): bool |
| 29 | + { |
| 30 | + return true; |
| 31 | + } |
| 32 | + |
| 33 | + public function rules(): array |
| 34 | + { |
| 35 | + return array_merge([ |
| 36 | + /* |
| 37 | + * Base our RuleSet on PER-CS2.0 Ruleset |
| 38 | + * https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/master/doc/ruleSets/PER-CS2.0.rst |
| 39 | + * https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/master/src/RuleSet/Sets/PERCS2x0Set.php |
| 40 | + */ |
| 41 | + '@PER-CS2.0' => true, |
| 42 | + |
| 43 | + /* |
| 44 | + * @Symfony |
| 45 | + */ |
| 46 | + 'php_unit_method_casing' => [ |
| 47 | + 'case' => 'snake_case', |
| 48 | + ], |
| 49 | + 'phpdoc_align' => [ |
| 50 | + 'align' => 'left', |
| 51 | + ], |
| 52 | + 'yoda_style' => [ |
| 53 | + 'equal' => false, |
| 54 | + 'identical' => false, |
| 55 | + 'less_and_greater' => false, |
| 56 | + ], |
| 57 | + 'align_multiline_comment' => true, |
| 58 | + 'single_line_throw' => false, |
| 59 | + 'phpdoc_order' => [ |
| 60 | + 'order' => [ |
| 61 | + 'param', |
| 62 | + 'return', |
| 63 | + 'throws', |
| 64 | + ], |
| 65 | + ], |
| 66 | + 'global_namespace_import' => [ |
| 67 | + 'import_classes' => false, |
| 68 | + 'import_functions' => false, |
| 69 | + 'import_constants' => false, |
| 70 | + ], |
| 71 | + |
| 72 | + /* |
| 73 | + * @Symfony:risky |
| 74 | + */ |
| 75 | + 'php_unit_test_annotation' => [ |
| 76 | + 'style' => 'annotation', |
| 77 | + ], |
| 78 | + 'native_function_invocation' => [ |
| 79 | + 'include' => [ |
| 80 | + NativeFunctionInvocationFixer::SET_INTERNAL, |
| 81 | + NativeFunctionInvocationFixer::SET_COMPILER_OPTIMIZED, |
| 82 | + ], |
| 83 | + 'scope' => 'namespaced', |
| 84 | + 'strict' => true, |
| 85 | + ], |
| 86 | + |
| 87 | + /* |
| 88 | + * @PER-CS2.0 overrides |
| 89 | + */ |
| 90 | + 'ordered_class_elements' => [ |
| 91 | + 'sort_algorithm' => 'none', |
| 92 | + 'order' => [ |
| 93 | + 'use_trait', |
| 94 | + 'constant_public', |
| 95 | + 'constant_protected', |
| 96 | + 'constant_private', |
| 97 | + 'property_public_static', |
| 98 | + 'property_public', |
| 99 | + 'property_protected_static', |
| 100 | + 'property_protected', |
| 101 | + 'property_private_static', |
| 102 | + 'property_private', |
| 103 | + 'method_public_static', |
| 104 | + 'method_protected_static', |
| 105 | + 'method_private_static', |
| 106 | + 'method_public_abstract_static', |
| 107 | + 'method_protected_abstract_static', |
| 108 | + 'method_public_abstract', |
| 109 | + 'method_protected_abstract', |
| 110 | + 'phpunit', |
| 111 | + 'method_public', |
| 112 | + 'method_protected', |
| 113 | + 'method_private', |
| 114 | + 'destruct', |
| 115 | + ], |
| 116 | + ], |
| 117 | + 'method_argument_space' => [ |
| 118 | + 'on_multiline' => 'ensure_fully_multiline', |
| 119 | + 'attribute_placement' => 'same_line', |
| 120 | + 'after_heredoc' => true, // @PHP73Migration |
| 121 | + ], |
| 122 | + |
| 123 | + /* |
| 124 | + * @PhpCsFixer |
| 125 | + */ |
| 126 | + 'method_chaining_indentation' => true, |
| 127 | + 'phpdoc_var_annotation_correct_order' => true, |
| 128 | + 'phpdoc_add_missing_param_annotation' => [ |
| 129 | + 'only_untyped' => true, |
| 130 | + ], |
| 131 | + 'multiline_comment_opening_closing' => true, |
| 132 | + 'self_static_accessor' => true, |
| 133 | + 'no_useless_else' => true, |
| 134 | + |
| 135 | + /* |
| 136 | + * @PhpCsFixer:risky |
| 137 | + */ |
| 138 | + 'static_lambda' => true, |
| 139 | + |
| 140 | + /* |
| 141 | + * @PHP**MigrationSet |
| 142 | + */ |
| 143 | + 'list_syntax' => [ |
| 144 | + 'syntax' => 'short', |
| 145 | + ], |
| 146 | + 'ternary_to_null_coalescing' => true, |
| 147 | + |
| 148 | + /* |
| 149 | + * @PHP**MigrationSet:risky |
| 150 | + */ |
| 151 | + 'random_api_migration' => true, |
| 152 | + 'declare_strict_types' => true, |
| 153 | + 'void_return' => true, |
| 154 | + |
| 155 | + /* |
| 156 | + * Rules without presets |
| 157 | + */ |
| 158 | + 'phpdoc_tag_casing' => true, |
| 159 | + ], $this->rules); |
| 160 | + } |
| 161 | +} |
0 commit comments