Conditions | 12 |
Paths | 50 |
Total Lines | 38 |
Code Lines | 31 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 156 |
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 |
||
18 | public static function readString($types, &$data) |
||
19 | { |
||
20 | if (!is_array($types)) { |
||
21 | $types = array($types); |
||
22 | } |
||
23 | $ok = false; |
||
24 | foreach ($types as $type) { |
||
25 | switch ($type) { |
||
26 | case self::OBJECT: |
||
27 | break; |
||
28 | case self::ARR: |
||
29 | break; |
||
30 | case self::STRING: |
||
31 | $ok = true; |
||
32 | break; |
||
33 | case self::NUMBER: |
||
34 | $newData = filter_var($data, FILTER_VALIDATE_FLOAT, FILTER_NULL_ON_FAILURE); |
||
35 | $ok = is_float($newData); |
||
36 | break; |
||
37 | case self::INTEGER: |
||
38 | $newData = filter_var($data, FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE); |
||
39 | $ok = is_int($newData); |
||
40 | break; |
||
41 | case self::BOOLEAN: |
||
42 | $newData = filter_var($data, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE); |
||
43 | $ok = is_bool($newData); |
||
44 | break; |
||
45 | case self::NULL: |
||
46 | break; |
||
47 | } |
||
48 | if ($ok) { |
||
49 | if (isset($newData)) { |
||
50 | $data = $newData; |
||
51 | } |
||
52 | return true; |
||
53 | } |
||
54 | } |
||
55 | return false; |
||
56 | } |
||
99 | } |