1 | <?php |
||
9 | class SapiEmitter implements Emitter |
||
10 | { |
||
11 | /** |
||
12 | * @param ResponseInterface $response |
||
13 | * @param null $maxBufferLevel |
||
14 | * |
||
15 | * @throws RuntimeException |
||
16 | */ |
||
17 | 7 | public function emit(ResponseInterface $response, $maxBufferLevel = null) |
|
35 | |||
36 | /** |
||
37 | * @param Response $response |
||
38 | */ |
||
39 | 6 | private function emitStatus(ResponseInterface $response) |
|
50 | |||
51 | /** |
||
52 | * @param ResponseInterface $response |
||
53 | */ |
||
54 | 6 | private function emitHeaders(ResponseInterface $response) |
|
69 | |||
70 | /** |
||
71 | * @param ResponseInterface $response |
||
72 | * @param $maxBufferLevel |
||
73 | */ |
||
74 | 6 | private function emitBody(ResponseInterface $response, $maxBufferLevel) |
|
86 | |||
87 | /** |
||
88 | * Filter a header name to wordcase |
||
89 | * |
||
90 | * @param string $header |
||
91 | * |
||
92 | * @return string |
||
93 | */ |
||
94 | 1 | private function filterHeader($header) |
|
101 | } |
||
102 |
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: