| Conditions | 10 |
| Paths | 13 |
| Total Lines | 34 |
| Code Lines | 17 |
| 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 |
||
| 15 | public static function checkTypes($vars) |
||
| 16 | { |
||
| 17 | if (!is_array($vars)) { |
||
| 18 | return false; |
||
| 19 | } |
||
| 20 | |||
| 21 | foreach ($vars as $var) { |
||
| 22 | if (!is_array($var)) { |
||
| 23 | return false; |
||
| 24 | } |
||
| 25 | |||
| 26 | if (!(!empty($var['type']) && isset($var['data']))) { |
||
| 27 | return false; |
||
| 28 | } |
||
| 29 | |||
| 30 | if (!is_string($var['type'])) { |
||
| 31 | return false; |
||
| 32 | } |
||
| 33 | |||
| 34 | if ($var['type'] === 'int') { |
||
| 35 | $var['type'] = 'integer'; |
||
| 36 | } |
||
| 37 | |||
| 38 | if ($var['type'] === 'float') { |
||
| 39 | $var['type'] = 'double'; |
||
| 40 | } |
||
| 41 | |||
| 42 | if (gettype($var['data']) !== $var['type']) { |
||
| 43 | return false; |
||
| 44 | } |
||
| 45 | } |
||
| 46 | |||
| 47 | return true; |
||
| 48 | } |
||
| 49 | } |