| Conditions | 3 |
| Paths | 3 |
| Total Lines | 13 |
| Code Lines | 8 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 12 |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 33 | protected function transformTokenToRoute($token, $value, array $query) |
||
| 34 | { |
||
| 35 | $query = parent::transformTokenToRoute($token, $value, $query); |
||
|
|
|||
| 36 | switch ($token) { |
||
| 37 | case ResourceImageDO::TOKEN_DIMENSION: |
||
| 38 | if ((int)$value !== ResourceImageDO::DEFAULT_DIMENSION) { |
||
| 39 | $query['size'] = $value; |
||
| 40 | } |
||
| 41 | break; |
||
| 42 | } |
||
| 43 | |||
| 44 | return $query; |
||
| 45 | } |
||
| 46 | } |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the parent class: