Conditions | 7 |
Paths | 7 |
Total Lines | 26 |
Lines | 0 |
Ratio | 0 % |
Tests | 14 |
CRAP Score | 7.0145 |
Changes | 0 |
1 | <?php |
||
65 | 14 | private function cast($value, $type) |
|
66 | { |
||
67 | 14 | switch ($type) { |
|
68 | 4 | case 'bool': |
|
69 | 1 | return boolval($value); |
|
70 | break; |
||
71 | 4 | case 'int': |
|
72 | 1 | return intval($value); |
|
73 | break; |
||
74 | 4 | case 'float': |
|
75 | 1 | return floatval($value); |
|
76 | break; |
||
77 | 4 | case 'string': |
|
78 | 5 | return $value; |
|
79 | break; |
||
80 | 4 | case 'array': |
|
81 | 1 | if (is_array($value)) { |
|
82 | 1 | return serialize($value); |
|
83 | } else { |
||
84 | return unserialize($value); |
||
85 | } |
||
86 | break; |
||
87 | default: |
||
88 | 5 | return $value; |
|
89 | } |
||
90 | } |
||
91 | } |
||
92 |
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idable
provides a methodequalsId
that in turn relies on the methodgetId()
. If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()
as an abstract method to the trait will make sure it is available.