Conditions | 3 |
Paths | 3 |
Total Lines | 14 |
Code Lines | 7 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php declare(strict_types=1); |
||
41 | public function supports(MessageInterface $message): bool |
||
42 | { |
||
43 | if (!class_exists(SfDumper::class)) { |
||
44 | return false; |
||
45 | } |
||
46 | |||
47 | if (!$message instanceof RequestInterface) { |
||
48 | return false; |
||
49 | } |
||
50 | |||
51 | [$contentType,] = explode(';', $message->getHeaderLine('Content-Type'), 2); |
||
52 | |||
53 | return 'application/json' === $contentType; |
||
54 | } |
||
55 | } |
||
56 |
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 implementation 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 interface: