| Conditions | 1 |
| Paths | 1 |
| Total Lines | 65 |
| Code Lines | 27 |
| 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 |
||
| 36 | public function arrayProvider(): array |
||
| 37 | { |
||
| 38 | $ns = new PhpNamespace('bar'); |
||
| 39 | $ns->addUse('A\B\C'); |
||
| 40 | |||
| 41 | return [ |
||
| 42 | [ |
||
| 43 | [1, 2, 3], |
||
| 44 | $ns, |
||
| 45 | <<<ARRAY |
||
| 46 | [ |
||
| 47 | 1, |
||
| 48 | 2, |
||
| 49 | 3, |
||
| 50 | ], |
||
| 51 | |||
| 52 | ARRAY |
||
| 53 | |||
| 54 | ], |
||
| 55 | [ |
||
| 56 | [1, ['a' => 'b'], new PhpLiteral('const')], |
||
| 57 | $ns, |
||
| 58 | <<<ARRAY |
||
| 59 | [ |
||
| 60 | 1, |
||
| 61 | [ |
||
| 62 | 'a' => 'b', |
||
| 63 | ], |
||
| 64 | const, |
||
| 65 | ], |
||
| 66 | |||
| 67 | ARRAY |
||
| 68 | |||
| 69 | ], |
||
| 70 | [ |
||
| 71 | [1, ['a' => 'b', 2]], |
||
| 72 | $ns, |
||
| 73 | <<<ARRAY |
||
| 74 | [ |
||
| 75 | 1, |
||
| 76 | [ |
||
| 77 | 'a' => 'b', |
||
| 78 | 0 => 2, |
||
| 79 | ], |
||
| 80 | ], |
||
| 81 | |||
| 82 | ARRAY |
||
| 83 | |||
| 84 | ], |
||
| 85 | [ |
||
| 86 | ['A\B\C::class', '\A\B\D::class'], |
||
| 87 | $ns, |
||
| 88 | <<<ARRAY |
||
| 89 | [ |
||
| 90 | C::class, |
||
| 91 | \A\B\D::class, |
||
| 92 | ], |
||
| 93 | |||
| 94 | ARRAY |
||
| 95 | |||
| 96 | ], |
||
| 97 | [ |
||
| 98 | ['{id:\d+}'], |
||
| 99 | $ns, |
||
| 100 | <<<ARRAY |
||
| 101 | [ |
||
| 111 |
Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.