| Conditions | 7 |
| Paths | 7 |
| Total Lines | 26 |
| Code Lines | 22 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 16 |
| CRAP Score | 7.0099 |
| Changes | 2 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 65 | 15 | private function cast($value, $type) |
|
| 66 | { |
||
| 67 | switch ($type) { |
||
| 68 | 15 | case 'bool': |
|
| 69 | 1 | return boolval($value); |
|
| 70 | break; |
||
| 71 | 14 | case 'int': |
|
| 72 | 1 | return intval($value); |
|
| 73 | break; |
||
| 74 | 13 | case 'float': |
|
| 75 | 1 | return floatval($value); |
|
| 76 | break; |
||
| 77 | 12 | case 'string': |
|
| 78 | 5 | return $value; |
|
| 79 | 6 | break; |
|
| 80 | 7 | case 'array': |
|
| 81 | 1 | if (is_array($value)) { |
|
| 82 | 1 | return serialize($value); |
|
| 83 | } else { |
||
| 84 | return unserialize($value); |
||
| 85 | } |
||
| 86 | break; |
||
| 87 | 6 | default: |
|
| 88 | 6 | return $value; |
|
| 89 | 7 | } |
|
| 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
Idableprovides a methodequalsIdthat 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.