| Conditions | 2 |
| Paths | 2 |
| Total Lines | 15 |
| Code Lines | 11 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 7 |
| CRAP Score | 2 |
| Changes | 0 | ||
| 1 | <?php |
||
| 34 | 16 | public function handle( |
|
| 35 | AbstractAnnotation $annotation, |
||
| 36 | ServiceMethodBuilder $serviceMethodBuilder, |
||
| 37 | ?Converter $converter, |
||
| 38 | ?int $index |
||
| 39 | ): void { |
||
| 40 | 16 | $uri = $annotation->getValue(); |
|
| 41 | |||
| 42 | 16 | $serviceMethodBuilder->setMethod($annotation->getType()); |
|
|
|
|||
| 43 | 16 | $serviceMethodBuilder->setPath($uri); |
|
| 44 | |||
| 45 | 16 | if (!$annotation->hasBody()) { |
|
| 46 | 11 | $serviceMethodBuilder->setHasBody($annotation->hasBody()); |
|
| 47 | } |
||
| 48 | 16 | } |
|
| 49 | } |
||
| 50 |
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: