Conditions | 12 |
Paths | 38 |
Total Lines | 36 |
Code Lines | 30 |
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 |
||
56 | public static function isValid($types, $data) |
||
57 | { |
||
58 | if (!is_array($types)) { |
||
59 | $types = array($types); |
||
60 | } |
||
61 | $ok = false; |
||
62 | foreach ($types as $type) { |
||
63 | switch ($type) { |
||
64 | case self::OBJECT: |
||
65 | $ok = $data instanceof \stdClass; |
||
66 | break; |
||
67 | case self::ARR: |
||
68 | $ok = is_array($data); |
||
69 | break; |
||
70 | case self::STRING: |
||
71 | $ok = is_string($data); |
||
72 | break; |
||
73 | case self::INTEGER: |
||
74 | $ok = is_int($data); |
||
75 | break; |
||
76 | case self::NUMBER: |
||
77 | $ok = is_int($data) || is_float($data); |
||
78 | break; |
||
79 | case self::BOOLEAN: |
||
80 | $ok = is_bool($data); |
||
81 | break; |
||
82 | case self::NULL: |
||
83 | $ok = null === $data; |
||
84 | break; |
||
85 | } |
||
86 | if ($ok) { |
||
87 | return true; |
||
88 | } |
||
89 | } |
||
90 | return false; |
||
91 | } |
||
92 | |||
94 | } |