|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace EsfahanAhan\PhpCsFixer; |
| 6 | + |
| 7 | +use PhpCsFixer\ConfigInterface; |
| 8 | +use PhpCsFixer\Finder; |
| 9 | + |
| 10 | +class Config extends \PhpCsFixer\Config |
| 11 | +{ |
| 12 | + public static function defaultRules(): array |
| 13 | + { |
| 14 | + return [ |
| 15 | + '@Symfony' => true, |
| 16 | + 'declare_strict_types' => true, |
| 17 | + 'modernize_types_casting' => true, |
| 18 | + 'no_useless_return' => true, |
| 19 | + 'ordered_class_elements' => [ |
| 20 | + 'order' => [ |
| 21 | + 'use_trait', |
| 22 | + 'constant_public', |
| 23 | + 'constant_protected', |
| 24 | + 'constant_private', |
| 25 | + 'property_public_static', |
| 26 | + 'property_protected_static', |
| 27 | + 'property_private_static', |
| 28 | + 'method_public_static', |
| 29 | + 'method_protected_static', |
| 30 | + 'method_private_static', |
| 31 | + 'property_public', |
| 32 | + 'property_protected', |
| 33 | + 'property_private', |
| 34 | + 'case', |
| 35 | + 'construct', |
| 36 | + 'destruct', |
| 37 | + 'magic', |
| 38 | + 'method_public', |
| 39 | + 'method_protected', |
| 40 | + 'method_private', |
| 41 | + ], |
| 42 | + ], |
| 43 | + 'php_unit_method_casing' => false, |
| 44 | + 'protected_to_private' => true, |
| 45 | + 'static_lambda' => true, |
| 46 | + 'strict_param' => true, |
| 47 | + 'single_quote' => true, |
| 48 | + 'trailing_comma_in_multiline' => [ |
| 49 | + 'elements' => [ |
| 50 | + 'arrays', |
| 51 | + ], |
| 52 | + ], |
| 53 | + 'use_arrow_functions' => true, |
| 54 | + 'whitespace_after_comma_in_array' => true, |
| 55 | + ]; |
| 56 | + } |
| 57 | + |
| 58 | + /** |
| 59 | + * @param string[] $folders |
| 60 | + * @param string[] $exclude folder to exclude |
| 61 | + */ |
| 62 | + public static function fromFolders(array $folders, ?string $target = null, array $exclude = []): ConfigInterface |
| 63 | + { |
| 64 | + $config = new static($target); |
| 65 | + |
| 66 | + return $config->setFinder( |
| 67 | + Finder::create()->in($folders)->exclude($exclude) |
| 68 | + ); |
| 69 | + } |
| 70 | + |
| 71 | + /** |
| 72 | + * @param string[] $folders |
| 73 | + */ |
| 74 | + public static function forLaravel(array $folders = [], ?string $target = null): ConfigInterface |
| 75 | + { |
| 76 | + $folders = array_merge(['app', 'config', 'database', 'routes', 'tests'], $folders); |
| 77 | + |
| 78 | + return static::fromFolders($folders, $target); |
| 79 | + } |
| 80 | + /** |
| 81 | + * The PHP version of the application. |
| 82 | + */ |
| 83 | + protected string $target; |
| 84 | + |
| 85 | + /** |
| 86 | + * Create a new MWL configuration. |
| 87 | + */ |
| 88 | + public function __construct(?string $target = null) |
| 89 | + { |
| 90 | + parent::__construct('esfahanahan'); |
| 91 | + |
| 92 | + $this->target = $target ?: PHP_VERSION; |
| 93 | + |
| 94 | + $this |
| 95 | + ->setRiskyAllowed(true) |
| 96 | + ->setRules( |
| 97 | + static::defaultRules() |
| 98 | + ); |
| 99 | + } |
| 100 | + |
| 101 | + /** |
| 102 | + * Merge a set of rules with the core ones. |
| 103 | + */ |
| 104 | + public function mergeRules(array $rules): ConfigInterface |
| 105 | + { |
| 106 | + return $this->setRules(array_merge( |
| 107 | + $this->getRules(), |
| 108 | + $rules |
| 109 | + )); |
| 110 | + } |
| 111 | + |
| 112 | + public function enablePhpunitRules(): ConfigInterface |
| 113 | + { |
| 114 | + return $this->mergeRules([ |
| 115 | + 'php_unit_dedicate_assert' => true, |
| 116 | + 'php_unit_dedicate_assert_internal_type' => true, |
| 117 | + 'php_unit_expectation' => true, |
| 118 | + 'php_unit_internal_class' => true, |
| 119 | + 'php_unit_mock' => true, |
| 120 | + 'php_unit_namespaced' => true, |
| 121 | + 'php_unit_no_expectation_annotation' => true, |
| 122 | + ]); |
| 123 | + } |
| 124 | +} |
0 commit comments