|
2 | 2 |
|
3 | 3 | declare(strict_types=1); |
4 | 4 |
|
5 | | -$config = new PhpCsFixer\Config(); |
6 | | -return $config |
7 | | - ->setCacheFile(__DIR__ . '/.cache/.php-cs-fixer.cache') |
8 | | - ->setFinder( |
9 | | - PhpCsFixer\Finder::create() |
10 | | - ->in([ |
11 | | - __DIR__, |
12 | | - ]) |
13 | | - ->exclude([ |
14 | | - __DIR__ . '/shell/translations.php', |
15 | | - ]) |
16 | | - ->name('*.php') |
17 | | - ->ignoreDotFiles(true) |
18 | | - ->ignoreVCS(true) |
| 5 | +/** |
| 6 | + * @copyright For copyright and license information, read the COPYING.txt file. |
| 7 | + * @link /COPYING.txt |
| 8 | + * @license Open Software License (OSL 3.0) |
| 9 | + */ |
| 10 | + |
| 11 | +use PhpCsFixer\Fixer as PhpCsFixer; |
| 12 | +use Symplify\EasyCodingStandard\Config\ECSConfig; |
| 13 | + |
| 14 | +return ECSConfig::configure() |
| 15 | + ->withPaths([ |
| 16 | + __DIR__ . '/app/Mage.php', |
| 17 | + __DIR__ . '/app/code/core', |
| 18 | + __DIR__ . '/dev', |
| 19 | + __DIR__ . '/errors', |
| 20 | + __DIR__ . '/lib/Mage', |
| 21 | + __DIR__ . '/lib/Magento', |
| 22 | + __DIR__ . '/lib/Varien', |
| 23 | + __DIR__ . '/shell', |
| 24 | + __DIR__ . '/tests', |
| 25 | + ]) |
| 26 | + ->withFileExtensions(['php']) |
| 27 | + ->withRootFiles() |
| 28 | + ->withCache(directory: __DIR__ . '/.cache/.ecs.cache') |
| 29 | + ->withPhpCsFixerSets(perCS30: true) |
| 30 | + ->withRules([ |
| 31 | + // RISKY: Replaces intval, floatval, doubleval, strval and boolval function calls with according type casting operators |
| 32 | + PhpCsFixer\CastNotation\ModernizeTypesCastingFixer::class, |
| 33 | + // RISKY: Use && and || logical operators instead of and and or |
| 34 | + PhpCsFixer\Operator\LogicalOperatorsFixer::class, |
| 35 | + // There should not be empty PHPDoc blocks |
| 36 | + PhpCsFixer\Phpdoc\NoEmptyPhpdocFixer::class, |
| 37 | + // PHPDoc annotation descriptions should not be a sentence |
| 38 | + PhpCsFixer\Phpdoc\PhpdocAnnotationWithoutDotFixer::class, |
| 39 | + // Docblocks should have the same indentation as the documented subject |
| 40 | + PhpCsFixer\Phpdoc\PhpdocIndentFixer::class, |
| 41 | + // Orders all @param annotations in DocBlocks according to method signature |
| 42 | + PhpCsFixer\Phpdoc\PhpdocParamOrderFixer::class, |
| 43 | + // Single line @var PHPDoc should have proper spacing |
| 44 | + PhpCsFixer\Phpdoc\PhpdocSingleLineVarSpacingFixer::class, |
| 45 | + // PHPDoc should start and end with content, excluding the very first and last line of the docblocks |
| 46 | + PhpCsFixer\Phpdoc\PhpdocTrimFixer::class, |
| 47 | + // Removes extra blank lines after summary and after description in PHPDoc |
| 48 | + PhpCsFixer\Phpdoc\PhpdocTrimConsecutiveBlankLineSeparationFixer::class, |
| 49 | + // @var and @type annotations must have type and name in the correct order |
| 50 | + PhpCsFixer\Phpdoc\PhpdocVarAnnotationCorrectOrderFixer::class, |
| 51 | + // @var and @type annotations of classy properties should not contain the name |
| 52 | + PhpCsFixer\Phpdoc\PhpdocVarWithoutNameFixer::class, |
| 53 | + ]) |
| 54 | + ->withConfiguredRule( |
| 55 | + // PHP84: Adds or removes ? before single type declarations or |null at the end of union types when parameters have a default null value. |
| 56 | + PhpCsFixer\FunctionNotation\NullableTypeDeclarationForDefaultNullValueFixer::class, |
| 57 | + ['use_nullable_type_declaration' => true], |
| 58 | + ) |
| 59 | + ->withConfiguredRule( |
| 60 | + // Sort union types and intersection types using configured order. |
| 61 | + PhpCsFixer\Operator\OperatorLinebreakFixer::class, |
| 62 | + ['only_booleans' => false, 'position' => 'beginning'], |
| 63 | + ) |
| 64 | + ->withConfiguredRule( |
| 65 | + // Operators - when multiline - must always be at the beginning or at the end of the line. |
| 66 | + PhpCsFixer\ClassNotation\OrderedTypesFixer::class, |
| 67 | + ['sort_algorithm' => 'alpha'], |
| 68 | + ) |
| 69 | + ->withConfiguredRule( |
| 70 | + // All items of the given PHPDoc tags must be either left-aligned or (by default) aligned vertically |
| 71 | + PhpCsFixer\Phpdoc\PhpdocAlignFixer::class, |
| 72 | + ['align' => 'vertical'], |
| 73 | + ) |
| 74 | + ->withConfiguredRule( |
| 75 | + // Annotations in PHPDoc should be ordered in defined sequence |
| 76 | + PhpCsFixer\Phpdoc\PhpdocOrderFixer::class, |
| 77 | + ['order' => ['param', 'return', 'throws', 'deprecated', 'see', 'SuppressWarnings', 'phpstan-ignore']], |
| 78 | + ) |
| 79 | + ->withConfiguredRule( |
| 80 | + // Annotations in PHPDoc should be ordered in defined sequence |
| 81 | + PhpCsFixer\Phpdoc\PhpdocOrderByValueFixer::class, |
| 82 | + ['annotations' => ['author', 'covers', 'group', 'method', 'throws', 'uses']], |
| 83 | + ) |
| 84 | + ->withConfiguredRule( |
| 85 | + // Fixes casing of PHPDoc tags |
| 86 | + PhpCsFixer\Phpdoc\PhpdocScalarFixer::class, |
| 87 | + ['types' => ['boolean', 'callback', 'double', 'integer', 'real', 'str']], |
| 88 | + ) |
| 89 | + ->withConfiguredRule( |
| 90 | + // Fixes casing of PHPDoc tags |
| 91 | + PhpCsFixer\Phpdoc\PhpdocTagCasingFixer::class, |
| 92 | + ['tags' => ['inheritDoc']], |
| 93 | + ) |
| 94 | + ->withConfiguredRule( |
| 95 | + // Sorts PHPDoc types |
| 96 | + PhpCsFixer\Phpdoc\PhpdocTypesOrderFixer::class, |
| 97 | + ['sort_algorithm' => 'alpha'], |
| 98 | + ) |
| 99 | + ->withConfiguredRule( |
| 100 | + // Calls to PHPUnit\Framework\TestCase static methods must all be of the same type, either $this->, self:: or static:: |
| 101 | + PhpCsFixer\PhpUnit\PhpUnitTestCaseStaticMethodCallsFixer::class, |
| 102 | + ['call_type' => 'self'], |
| 103 | + ) |
| 104 | + ->withConfiguredRule( |
| 105 | + // There MUST NOT be more than one property or constant declared per statement. |
| 106 | + PhpCsFixer\ClassNotation\SingleClassElementPerStatementFixer::class, |
| 107 | + ['elements' => ['const', 'property']], |
| 108 | + ) |
| 109 | + ->withConfiguredRule( |
| 110 | + // Convert double quotes to single quotes for simple strings. |
| 111 | + PhpCsFixer\StringNotation\SingleQuoteFixer::class, |
| 112 | + ['strings_containing_single_quote_chars' => false], |
| 113 | + ) |
| 114 | + ->withConfiguredRule( |
| 115 | + // Arguments lists, array destructuring lists, arrays that are multi-line, match-lines and parameters lists must have a trailing comma. |
| 116 | + // removed "match" and "parameters" for PHP7 |
| 117 | + // see https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/8308 |
| 118 | + PhpCsFixer\ControlStructure\TrailingCommaInMultilineFixer::class, |
| 119 | + ['after_heredoc' => true, 'elements' => ['arguments', 'array_destructuring', 'arrays']], |
19 | 120 | ) |
20 | | - ->setRiskyAllowed(true) |
21 | | - ->setRules([ |
22 | | - // see https://cs.symfony.com/doc/ruleSets/PER-CS2.0.html |
23 | | - '@PER-CS2x0' => true, |
24 | | - // RISKY: Use && and || logical operators instead of and and or. |
25 | | - 'logical_operators' => true, |
26 | | - // RISKY: Replaces intval, floatval, doubleval, strval and boolval function calls with according type casting operator. |
27 | | - 'modernize_types_casting' => true, |
28 | | - // There should not be empty PHPDoc blocks. |
29 | | - 'no_empty_phpdoc' => true, |
30 | | - // PHP84: Adds or removes ? before single type declarations or |null at the end of union types when parameters have a default null value. |
31 | | - 'nullable_type_declaration_for_default_null_value' => true, |
32 | | - // Operators - when multiline - must always be at the beginning or at the end of the line. |
33 | | - 'operator_linebreak' => true, |
34 | | - // Sort union types and intersection types using configured order. |
35 | | - 'ordered_types' => true, |
36 | | - // Calls to PHPUnit\Framework\TestCase static methods must all be of the same type, either $this->, self:: or static:: |
37 | | - 'php_unit_test_case_static_method_calls' => ['call_type' => 'self'], |
38 | | - // PHPDoc annotation descriptions should not be a sentence. |
39 | | - 'phpdoc_annotation_without_dot' => true, |
40 | | - // All items of the given PHPDoc tags must be either left-aligned or (by default) aligned vertically. |
41 | | - 'phpdoc_align' => true, |
42 | | - // Docblocks should have the same indentation as the documented subject. |
43 | | - 'phpdoc_indent' => true, |
44 | | - // Annotations in PHPDoc should be ordered in defined sequence. |
45 | | - 'phpdoc_order' => ['order' => ['param', 'return', 'throws', 'deprecated', 'see', 'SuppressWarnings', 'phpstan-ignore']], |
46 | | - // Order PHPDoc tags by value. |
47 | | - 'phpdoc_order_by_value' => ['annotations' => ['author', 'covers', 'group', 'method', 'throws', 'uses']], |
48 | | - // Orders all @param annotations in DocBlocks according to method signature. |
49 | | - 'phpdoc_param_order' => true, |
50 | | - // PHPDoc should start and end with content, excluding the very first and last line of the docblocks. |
51 | | - 'phpdoc_trim' => true, |
52 | | - // Removes extra blank lines after summary and after description in PHPDoc. |
53 | | - 'phpdoc_trim_consecutive_blank_line_separation' => true, |
54 | | - // Scalar types should always be written in the same form. int not integer, bool not boolean, float not real or double. |
55 | | - 'phpdoc_scalar' => true, |
56 | | - // Single line @var PHPDoc should have proper spacing. |
57 | | - 'phpdoc_single_line_var_spacing' => true, |
58 | | - // Fixes casing of PHPDoc tags. |
59 | | - 'phpdoc_tag_casing' => true, |
60 | | - // Sorts PHPDoc types. |
61 | | - 'phpdoc_types_order' => true, |
62 | | - // @var and @type annotations must have type and name in the correct order. |
63 | | - 'phpdoc_var_annotation_correct_order' => true, |
64 | | - // @var and @type annotations of classy properties should not contain the name. |
65 | | - 'phpdoc_var_without_name' => true, |
66 | | - // There MUST NOT be more than one property or constant declared per statement. |
67 | | - 'single_class_element_per_statement' => true, |
68 | | - // Convert double quotes to single quotes for simple strings. |
69 | | - 'single_quote' => true, |
70 | | - // Arguments lists, array destructuring lists, arrays that are multi-line, match-lines and parameters lists must have a trailing comma. |
71 | | - // removed "match" and "parameters" for PHP7 |
72 | | - // see https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/8308 |
73 | | - 'trailing_comma_in_multiline' => ['after_heredoc' => true, 'elements' => ['arguments', 'array_destructuring', 'arrays']], |
74 | | - // A single space or none should be around union type and intersection type operators. |
75 | | - 'types_spaces' => true, |
76 | | - ]); |
| 121 | + ->withConfiguredRule( |
| 122 | + // A single space or none should be around union type and intersection type operators |
| 123 | + PhpCsFixer\Whitespace\TypesSpacesFixer::class, |
| 124 | + ['space' => 'none'], |
| 125 | + ); |
0 commit comments