1 | <?php |
||
36 | class Listener implements ListenerContract |
||
37 | { |
||
38 | /** |
||
39 | * Holds an instance of the writer. |
||
40 | * |
||
41 | * @var \NunoMaduro\Collision\Contracts\Writer |
||
42 | */ |
||
43 | protected $writer; |
||
44 | |||
45 | /** |
||
46 | * Creates a new instance of the class. |
||
47 | * |
||
48 | * @param \NunoMaduro\Collision\Contracts\Writer|null $writer |
||
49 | */ |
||
50 | 2 | public function __construct(WriterContract $writer = null) |
|
54 | |||
55 | /** |
||
56 | * {@inheritdoc} |
||
57 | */ |
||
58 | 1 | public function render(Test $test, \Throwable $throwable) |
|
93 | |||
94 | /** |
||
95 | * {@inheritdoc} |
||
96 | */ |
||
97 | public function addError(Test $test, \Throwable $throwable, float $time): void |
||
101 | |||
102 | /** |
||
103 | * {@inheritdoc} |
||
104 | */ |
||
105 | 1 | public function addWarning(Test $test, Warning $t, float $time): void |
|
108 | |||
109 | /** |
||
110 | * {@inheritdoc} |
||
111 | */ |
||
112 | 1 | public function addFailure(Test $test, AssertionFailedError $throwable, float $time): void |
|
125 | |||
126 | /** |
||
127 | * {@inheritdoc} |
||
128 | */ |
||
129 | 1 | public function addIncompleteTest(Test $test, \Throwable $t, float $time): void |
|
132 | |||
133 | /** |
||
134 | * {@inheritdoc} |
||
135 | */ |
||
136 | 1 | public function addRiskyTest(Test $test, \Throwable $t, float $time): void |
|
139 | |||
140 | /** |
||
141 | * {@inheritdoc} |
||
142 | */ |
||
143 | 1 | public function addSkippedTest(Test $test, \Throwable $t, float $time): void |
|
146 | |||
147 | /** |
||
148 | * {@inheritdoc} |
||
149 | */ |
||
150 | 1 | public function startTestSuite(TestSuite $suite): void |
|
153 | |||
154 | /** |
||
155 | * {@inheritdoc} |
||
156 | */ |
||
157 | 1 | public function endTestSuite(TestSuite $suite): void |
|
160 | |||
161 | /** |
||
162 | * {@inheritdoc} |
||
163 | */ |
||
164 | 1 | public function startTest(Test $test): void |
|
167 | |||
168 | /** |
||
169 | * {@inheritdoc} |
||
170 | */ |
||
171 | 1 | public function endTest(Test $test, float $time): void |
|
174 | |||
175 | /** |
||
176 | * Builds an Writer. |
||
177 | * |
||
178 | * @return \NunoMaduro\Collision\Contracts\Writer |
||
179 | */ |
||
180 | 1 | protected function buildWriter(): WriterContract |
|
192 | |||
193 | /** |
||
194 | * Terminates the test. |
||
195 | */ |
||
196 | public function terminate(): void |
||
200 | } |
||
201 | } |
||
202 |
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: