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