|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Netgen\CodingStandard\PhpCsFixer; |
| 6 | + |
| 7 | +use PhpCsFixer\Config as BaseConfig; |
| 8 | + |
| 9 | +final class Config extends BaseConfig |
| 10 | +{ |
| 11 | + public function __construct(string $name = 'default') |
| 12 | + { |
| 13 | + parent::__construct($name); |
| 14 | + |
| 15 | + $this->setCodeStyleRules(); |
| 16 | + } |
| 17 | + |
| 18 | + /** |
| 19 | + * @param array<string, mixed> $rules |
| 20 | + */ |
| 21 | + public function addRules(array $rules): self |
| 22 | + { |
| 23 | + $this->setRules([...$this->getRules(), ...$rules]); |
| 24 | + |
| 25 | + return $this; |
| 26 | + } |
| 27 | + |
| 28 | + private function setCodeStyleRules(): void |
| 29 | + { |
| 30 | + $this |
| 31 | + ->setRiskyAllowed(true) |
| 32 | + ->setRules( |
| 33 | + [ |
| 34 | + '@PER-CS' => true, |
| 35 | + '@PER-CS:risky' => true, |
| 36 | + '@PhpCsFixer' => true, |
| 37 | + '@PhpCsFixer:risky' => true, |
| 38 | + |
| 39 | + // Overrides for rules included in PhpCsFixer rule sets |
| 40 | + 'concat_space' => ['spacing' => 'one'], |
| 41 | + 'fully_qualified_strict_types' => ['phpdoc_tags' => []], |
| 42 | + 'method_chaining_indentation' => false, |
| 43 | + 'multiline_promoted_properties' => true, |
| 44 | + 'multiline_whitespace_before_semicolons' => false, |
| 45 | + 'native_function_invocation' => ['include' => ['@all']], |
| 46 | + 'no_superfluous_phpdoc_tags' => false, |
| 47 | + 'no_unset_on_property' => false, |
| 48 | + 'operator_linebreak' => false, |
| 49 | + 'ordered_imports' => ['imports_order' => ['class', 'function', 'const'], 'sort_algorithm' => 'alpha'], |
| 50 | + 'ordered_types' => ['null_adjustment' => 'always_last', 'sort_algorithm' => 'none'], |
| 51 | + 'php_unit_data_provider_method_order' => false, |
| 52 | + 'php_unit_data_provider_name' => false, |
| 53 | + 'php_unit_internal_class' => false, |
| 54 | + 'php_unit_test_case_static_method_calls' => false, |
| 55 | + 'php_unit_test_class_requires_covers' => false, |
| 56 | + 'phpdoc_align' => false, |
| 57 | + 'phpdoc_order' => ['order' => ['param', 'throws', 'return']], |
| 58 | + 'phpdoc_types_order' => ['null_adjustment' => 'always_last', 'sort_algorithm' => 'none'], |
| 59 | + 'single_line_comment_style' => false, |
| 60 | + 'trailing_comma_in_multiline' => ['elements' => ['arrays', 'arguments', 'match', 'parameters']], |
| 61 | + 'yoda_style' => ['equal' => false, 'identical' => false, 'less_and_greater' => false], |
| 62 | + |
| 63 | + // Additional rules |
| 64 | + 'date_time_immutable' => true, |
| 65 | + 'declare_strict_types' => true, |
| 66 | + 'global_namespace_import' => [ |
| 67 | + 'import_classes' => null, |
| 68 | + 'import_constants' => true, |
| 69 | + 'import_functions' => true, |
| 70 | + ], |
| 71 | + 'heredoc_indentation' => ['indentation' => 'same_as_start'], |
| 72 | + 'mb_str_functions' => true, |
| 73 | + 'native_constant_invocation' => true, |
| 74 | + 'nullable_type_declaration_for_default_null_value' => true, |
| 75 | + 'static_lambda' => true, |
| 76 | + 'ternary_to_null_coalescing' => true, |
| 77 | + 'use_arrow_functions' => true, |
| 78 | + ], |
| 79 | + ); |
| 80 | + } |
| 81 | +} |
0 commit comments