| Total Lines | 74 |
| Code Lines | 44 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 35 | return static function (ECSConfig $ecsConfig): void { |
||
| 36 | $ecsConfig->paths([ |
||
| 37 | __DIR__ . '/src', |
||
| 38 | __DIR__ . '/tests', |
||
| 39 | ]); |
||
| 40 | |||
| 41 | $ecsConfig->sets([SetList::PSR_12, SetList::CLEAN_CODE, SetList::COMMON]); |
||
| 42 | |||
| 43 | $ruleConfigurations = [ |
||
| 44 | [ |
||
| 45 | IncrementStyleFixer::class, |
||
| 46 | ['style' => 'post'], |
||
| 47 | ], |
||
| 48 | [ |
||
| 49 | CastSpacesFixer::class, |
||
| 50 | ['space' => 'none'], |
||
| 51 | ], |
||
| 52 | [ |
||
| 53 | YodaStyleFixer::class, |
||
| 54 | [ |
||
| 55 | 'equal' => false, |
||
| 56 | 'identical' => false, |
||
| 57 | 'less_and_greater' => false, |
||
| 58 | ], |
||
| 59 | ], |
||
| 60 | [ |
||
| 61 | ConcatSpaceFixer::class, |
||
| 62 | ['spacing' => 'one'], |
||
| 63 | ], |
||
| 64 | [ |
||
| 65 | CastSpacesFixer::class, |
||
| 66 | ['space' => 'none'], |
||
| 67 | ], |
||
| 68 | [ |
||
| 69 | OrderedImportsFixer::class, |
||
| 70 | ['imports_order' => ['class', 'function', 'const']], |
||
| 71 | ], |
||
| 72 | [ |
||
| 73 | NoSuperfluousPhpdocTagsFixer::class, |
||
| 74 | [ |
||
| 75 | 'remove_inheritdoc' => false, |
||
| 76 | 'allow_mixed' => true, |
||
| 77 | 'allow_unused_params' => false, |
||
| 78 | ], |
||
| 79 | ], |
||
| 80 | [ |
||
| 81 | DeclareEqualNormalizeFixer::class, |
||
| 82 | ['space' => 'single'], |
||
| 83 | ], |
||
| 84 | [ |
||
| 85 | BlankLineBeforeStatementFixer::class, |
||
| 86 | ['statements' => ['continue', 'declare', 'return', 'throw', 'try']], |
||
| 87 | ], |
||
| 88 | [ |
||
| 89 | BinaryOperatorSpacesFixer::class, |
||
| 90 | ['operators' => ['&' => 'align']], |
||
| 91 | ], |
||
| 92 | ]; |
||
| 93 | |||
| 94 | array_map(static fn ($parameters) => $ecsConfig->ruleWithConfiguration(...$parameters), $ruleConfigurations); |
||
|
|
|||
| 95 | |||
| 96 | $ecsConfig->skip([ |
||
| 97 | NoMultilineWhitespaceAroundDoubleArrowFixer::class => null, |
||
| 98 | PhpdocNoPackageFixer::class => null, |
||
| 99 | PhpdocSummaryFixer::class => null, |
||
| 100 | PhpdocSeparationFixer::class => null, |
||
| 101 | BlankLineAfterOpeningTagFixer::class => null, |
||
| 102 | ClassAttributesSeparationFixer::class => null, |
||
| 103 | NoBlankLinesBeforeNamespaceFixer::class => null, |
||
| 104 | NotOperatorWithSuccessorSpaceFixer::class => null, |
||
| 105 | SingleLineThrowFixer::class => null, |
||
| 106 | PhpdocAlignFixer::class => null, |
||
| 107 | PhpdocToCommentFixer::class => null, |
||
| 108 | NativeFunctionInvocationFixer::class => null, |
||
| 109 | ]); |
||
| 111 |
This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.