| Conditions | 10 |
| Paths | 9 |
| Total Lines | 33 |
| Code Lines | 19 |
| 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 |
||
| 32 | public static function checkType(array $vars): bool |
||
| 33 | { |
||
| 34 | foreach ($vars as $var) { |
||
| 35 | if (!is_array($var)) { |
||
| 36 | throw new Exception( |
||
| 37 | 'The informations need for the check is not in a correct format.', |
||
| 38 | self::ERR_CHECKTYPE_INFOS_FORMAT |
||
| 39 | ); |
||
| 40 | } |
||
| 41 | |||
| 42 | if ( |
||
| 43 | !isset($var['data']) |
||
| 44 | || empty($var['type']) |
||
| 45 | || (isset($var['type']) && !is_string($var['type'])) |
||
| 46 | ) { |
||
| 47 | throw new Exception( |
||
| 48 | 'Items data or type is empty or in an bad format.', |
||
| 49 | self::ERR_CHECKTYPE_DATA_OR_TYPE_VALUE_FORMAT |
||
| 50 | ); |
||
| 51 | } |
||
| 52 | |||
| 53 | if ($var['type'] === 'int') { |
||
| 54 | $var['type'] = 'integer'; |
||
| 55 | } elseif ($var['type'] === 'float') { |
||
| 56 | $var['type'] = 'double'; |
||
| 57 | } |
||
| 58 | |||
| 59 | if (gettype($var['data']) !== $var['type']) { |
||
| 60 | return false; |
||
| 61 | } |
||
| 62 | } |
||
| 63 | |||
| 64 | return true; |
||
| 65 | } |
||
| 85 |