| Conditions | 2 |
| Paths | 2 |
| Total Lines | 70 |
| Code Lines | 64 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 101 | public function setStatus($status) |
||
| 102 | { |
||
| 103 | $validStatus = [ |
||
| 104 | 100, |
||
| 105 | 101, |
||
| 106 | 102, |
||
| 107 | 200, |
||
| 108 | 201, |
||
| 109 | 202, |
||
| 110 | 203, |
||
| 111 | 204, |
||
| 112 | 205, |
||
| 113 | 206, |
||
| 114 | 207, |
||
| 115 | 208, |
||
| 116 | 300, |
||
| 117 | 301, |
||
| 118 | 302, |
||
| 119 | 303, |
||
| 120 | 304, |
||
| 121 | 305, |
||
| 122 | 306, |
||
| 123 | 307, |
||
| 124 | 400, |
||
| 125 | 401, |
||
| 126 | 402, |
||
| 127 | 403, |
||
| 128 | 404, |
||
| 129 | 405, |
||
| 130 | 406, |
||
| 131 | 407, |
||
| 132 | 408, |
||
| 133 | 409, |
||
| 134 | 410, |
||
| 135 | 411, |
||
| 136 | 412, |
||
| 137 | 413, |
||
| 138 | 414, |
||
| 139 | 415, |
||
| 140 | 416, |
||
| 141 | 417, |
||
| 142 | 418, |
||
| 143 | 422, |
||
| 144 | 423, |
||
| 145 | 424, |
||
| 146 | 425, |
||
| 147 | 426, |
||
| 148 | 428, |
||
| 149 | 429, |
||
| 150 | 431, |
||
| 151 | 500, |
||
| 152 | 501, |
||
| 153 | 502, |
||
| 154 | 503, |
||
| 155 | 504, |
||
| 156 | 505, |
||
| 157 | 506, |
||
| 158 | 507, |
||
| 159 | 508, |
||
| 160 | 511, |
||
| 161 | ]; |
||
| 162 | |||
| 163 | if (false === in_array($status, $validStatus, false)) { |
||
| 164 | throw new \InvalidArgumentException(sprintf( |
||
| 165 | 'Provided status does not match a valid HTTP Status Code.', |
||
| 166 | $status |
||
| 167 | )); |
||
| 168 | } |
||
| 169 | $this->status = (int) $status; |
||
| 170 | } |
||
| 171 | |||
| 260 |