Conditions | 5 |
Paths | 5 |
Total Lines | 19 |
Code Lines | 16 |
Lines | 0 |
Ratio | 0 % |
Tests | 9 |
CRAP Score | 5.3906 |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
49 | 4 | private function cast($value, $type) |
|
50 | { |
||
51 | switch ($type) { |
||
52 | 4 | case 'bool': |
|
53 | 1 | return boolval($value); |
|
54 | break; |
||
55 | 3 | case 'int': |
|
56 | 1 | return intval($value); |
|
57 | break; |
||
58 | 2 | case 'float': |
|
59 | 1 | return floatval($value); |
|
60 | break; |
||
61 | 1 | case 'string': |
|
62 | 1 | return $value; |
|
63 | break; |
||
64 | default: |
||
65 | return $value; |
||
66 | } |
||
67 | } |
||
68 | } |
||
69 |
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.