| Conditions | 16 |
| Paths | 16 |
| Total Lines | 46 |
| Code Lines | 31 |
| 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 |
||
| 29 | protected function checkType($type, $value) |
||
| 30 | { |
||
| 31 | switch ($type) { |
||
| 32 | case 'array': |
||
| 33 | return is_array($value); |
||
| 34 | |||
| 35 | case 'bool': |
||
| 36 | case 'boolean': |
||
| 37 | return is_bool($value); |
||
| 38 | |||
| 39 | case 'callable': |
||
| 40 | return is_callable($value); |
||
| 41 | |||
| 42 | case 'float': |
||
| 43 | case 'double': |
||
| 44 | return is_float($value); |
||
| 45 | |||
| 46 | case 'int': |
||
| 47 | case 'integer': |
||
| 48 | return is_int($value); |
||
| 49 | |||
| 50 | case 'null': |
||
| 51 | return is_null($value); |
||
| 52 | |||
| 53 | case 'numeric': |
||
| 54 | return is_numeric($value); |
||
| 55 | |||
| 56 | case 'object': |
||
| 57 | return is_object($value); |
||
| 58 | |||
| 59 | case 'resource': |
||
| 60 | return is_resource($value); |
||
| 61 | |||
| 62 | case 'scalar': |
||
| 63 | return is_scalar($value); |
||
| 64 | |||
| 65 | case 'string': |
||
| 66 | return is_string($value); |
||
| 67 | |||
| 68 | case 'mixed': |
||
| 69 | return true; |
||
| 70 | |||
| 71 | default: |
||
| 72 | return ($value instanceof $type); |
||
| 73 | } |
||
| 74 | } |
||
| 75 | } |
||
| 76 |