| Conditions | 4 | 
| Paths | 5 | 
| Total Lines | 22 | 
| Code Lines | 11 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 0 | ||
| 1 | <?php declare(strict_types=1);  | 
            ||
| 16 | public function dump(MessageInterface $message, array $headers): void  | 
            ||
| 17 |     { | 
            ||
| 18 |         if (!$this->supports($message)) { | 
            ||
| 19 | throw new UnsupportedMessage($message, ResponseInterface::class);  | 
            ||
| 20 | }  | 
            ||
| 21 | |||
| 22 | echo "\n";  | 
            ||
| 23 | |||
| 24 |         printf(self::TEMPLATE, 'Response status', "{$message->getStatusCode()} {$message->getReasonPhrase()}"); | 
            ||
| 25 | |||
| 26 |         foreach ($headers as $header) { | 
            ||
| 27 |             printf(self::TEMPLATE, "Response {$header}", $message->getHeaderLine($header)); | 
            ||
| 28 | }  | 
            ||
| 29 | |||
| 30 | $body = (string) $message->getBody();  | 
            ||
| 31 | |||
| 32 |         if (!empty($body)) { | 
            ||
| 33 |             echo "\n{$body}"; | 
            ||
| 34 | }  | 
            ||
| 35 | |||
| 36 | echo "\n";  | 
            ||
| 37 | }  | 
            ||
| 38 | |||
| 44 | 
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: