| Conditions | 1 |
| Paths | 1 |
| Total Lines | 109 |
| Code Lines | 62 |
| 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 |
||
| 27 | public function providesArraysSortedByKey() |
||
| 28 | { |
||
| 29 | return [[ |
||
| 30 | [ |
||
| 31 | 'baz' => 'qux', |
||
| 32 | 'foo' => 'bar', |
||
| 33 | ], |
||
| 34 | [ |
||
| 35 | 'foo' => 'bar', |
||
| 36 | 'baz' => 'qux', |
||
| 37 | ], |
||
| 38 | [], |
||
| 39 | ], [ |
||
| 40 | [ |
||
| 41 | 'foo', |
||
| 42 | 'bar', |
||
| 43 | 'baz', |
||
| 44 | ], |
||
| 45 | [ |
||
| 46 | 'foo', |
||
| 47 | 'bar', |
||
| 48 | 'baz', |
||
| 49 | ], |
||
| 50 | [], |
||
| 51 | ], [ |
||
| 52 | [ |
||
| 53 | 1 => 'baz', |
||
| 54 | 2 => 'bar', |
||
| 55 | 3 => 'foo', |
||
| 56 | ], |
||
| 57 | [ |
||
| 58 | 3 => 'foo', |
||
| 59 | 2 => 'bar', |
||
| 60 | 1 => 'baz', |
||
| 61 | ], |
||
| 62 | [], |
||
| 63 | ], [ //Order array contains the same number of keys. |
||
| 64 | [ |
||
| 65 | 'corge' => 'grault', |
||
| 66 | 'foo' => 'bar', |
||
| 67 | 'quux' => 'quuz', |
||
| 68 | 'baz' => 'qux', |
||
| 69 | ], |
||
| 70 | [ |
||
| 71 | 'foo' => 'bar', |
||
| 72 | 'baz' => 'qux', |
||
| 73 | 'quux' => 'quuz', |
||
| 74 | 'corge' => 'grault', |
||
| 75 | ], |
||
| 76 | [ |
||
| 77 | 'corge', |
||
| 78 | 'foo', |
||
| 79 | 'quux', |
||
| 80 | 'baz', |
||
| 81 | ], |
||
| 82 | ], [ //Order array contains fewer keys. |
||
| 83 | [ |
||
| 84 | 'corge' => 'grault', |
||
| 85 | 'foo' => 'bar', |
||
| 86 | 'baz' => 'qux', |
||
| 87 | 'quux' => 'quuz', |
||
| 88 | ], |
||
| 89 | [ |
||
| 90 | 'foo' => 'bar', |
||
| 91 | 'baz' => 'qux', |
||
| 92 | 'quux' => 'quuz', |
||
| 93 | 'corge' => 'grault', |
||
| 94 | ], |
||
| 95 | [ |
||
| 96 | 'corge', |
||
| 97 | 'foo', |
||
| 98 | ], |
||
| 99 | ], [ //Order array contains extra keys. |
||
| 100 | [ |
||
| 101 | 'corge' => 'grault', |
||
| 102 | 'foo' => 'bar', |
||
| 103 | 'quux' => 'quuz', |
||
| 104 | 'baz' => 'qux', |
||
| 105 | ], |
||
| 106 | [ |
||
| 107 | 'foo' => 'bar', |
||
| 108 | 'baz' => 'qux', |
||
| 109 | 'quux' => 'quuz', |
||
| 110 | 'corge' => 'grault', |
||
| 111 | ], |
||
| 112 | [ |
||
| 113 | 'corge', |
||
| 114 | 'foo', |
||
| 115 | 'quux', |
||
| 116 | 'baz', |
||
| 117 | 'garply', |
||
| 118 | 'waldo', |
||
| 119 | ], |
||
| 120 | ], [ //Numeric keys and explicit order. |
||
| 121 | [ |
||
| 122 | 56 => 'bar', |
||
| 123 | 2 => 'baz', |
||
| 124 | 23 => 'foo', |
||
| 125 | 17 => 'qux', |
||
| 126 | ], |
||
| 127 | [ |
||
| 128 | 23 => 'foo', |
||
| 129 | 56 => 'bar', |
||
| 130 | 2 => 'baz', |
||
| 131 | 17 => 'qux', |
||
| 132 | ], |
||
| 133 | [ |
||
| 134 | 56, |
||
| 135 | 2, |
||
| 136 | ], |
||
| 359 |