1 | <?php |
||
31 | class Writer implements WriterContract |
||
32 | { |
||
33 | /** |
||
34 | * The number of frames if no verbosity is specified. |
||
35 | */ |
||
36 | const VERBOSITY_NORMAL_FRAMES = 1; |
||
37 | |||
38 | /** |
||
39 | * Holds an instance of the Output. |
||
40 | * |
||
41 | * @var \Symfony\Component\Console\Output\OutputInterface |
||
42 | */ |
||
43 | protected $output; |
||
44 | |||
45 | /** |
||
46 | * Holds an instance of the Argument Formatter. |
||
47 | * |
||
48 | * @var \NunoMaduro\Collision\Contracts\ArgumentFormatter |
||
49 | */ |
||
50 | protected $argumentFormatter; |
||
51 | |||
52 | /** |
||
53 | * Holds an instance of the Highlighter. |
||
54 | * |
||
55 | * @var \NunoMaduro\Collision\Contracts\Highlighter |
||
56 | */ |
||
57 | protected $highlighter; |
||
58 | |||
59 | /** |
||
60 | * Ignores traces where the file string matches one |
||
61 | * of the provided regex expressions. |
||
62 | * |
||
63 | * @var string[] |
||
64 | */ |
||
65 | protected $ignore = []; |
||
66 | |||
67 | /** |
||
68 | * Declares whether or not the trace should appear. |
||
69 | * |
||
70 | * @var bool |
||
71 | */ |
||
72 | protected $showTrace = true; |
||
73 | |||
74 | /** |
||
75 | * Declares whether or not the editor should appear. |
||
76 | * |
||
77 | * @var bool |
||
78 | */ |
||
79 | protected $showEditor = true; |
||
80 | |||
81 | /** |
||
82 | * Creates an instance of the writer. |
||
83 | * |
||
84 | * @param \Symfony\Component\Console\Output\OutputInterface|null $output |
||
85 | * @param \NunoMaduro\Collision\Contracts\ArgumentFormatter|null $argumentFormatter |
||
86 | * @param \NunoMaduro\Collision\Contracts\Highlighter|null $highlighter |
||
87 | */ |
||
88 | 14 | public function __construct( |
|
98 | |||
99 | /** |
||
100 | * {@inheritdoc} |
||
101 | */ |
||
102 | 5 | public function write(Inspector $inspector): void |
|
122 | |||
123 | /** |
||
124 | * {@inheritdoc} |
||
125 | */ |
||
126 | 1 | public function ignoreFilesIn(array $ignore): WriterContract |
|
132 | |||
133 | /** |
||
134 | * {@inheritdoc} |
||
135 | */ |
||
136 | 1 | public function showTrace(bool $show): WriterContract |
|
142 | |||
143 | /** |
||
144 | * {@inheritdoc} |
||
145 | */ |
||
146 | 1 | public function showEditor(bool $show): WriterContract |
|
152 | |||
153 | /** |
||
154 | * {@inheritdoc} |
||
155 | */ |
||
156 | 2 | public function setOutput(OutputInterface $output): WriterContract |
|
162 | |||
163 | /** |
||
164 | * {@inheritdoc} |
||
165 | */ |
||
166 | 7 | public function getOutput(): OutputInterface |
|
170 | |||
171 | /** |
||
172 | * Returns pertinent frames. |
||
173 | * |
||
174 | * @param \Whoops\Exception\Inspector $inspector |
||
175 | * |
||
176 | * @return array |
||
177 | */ |
||
178 | 5 | protected function getFrames(Inspector $inspector): array |
|
194 | |||
195 | /** |
||
196 | * Renders the title of the exception. |
||
197 | * |
||
198 | * @param \Whoops\Exception\Inspector $inspector |
||
199 | * |
||
200 | * @return \NunoMaduro\Collision\Contracts\Writer |
||
201 | */ |
||
202 | 5 | protected function renderTitle(Inspector $inspector): WriterContract |
|
213 | |||
214 | /** |
||
215 | * Renders the solution of the exception, if any. |
||
216 | * |
||
217 | * @param \Whoops\Exception\Inspector $inspector |
||
218 | * |
||
219 | * @return \NunoMaduro\Collision\Contracts\Writer |
||
220 | */ |
||
221 | 5 | protected function renderSolution(Inspector $inspector): WriterContract |
|
250 | |||
251 | /** |
||
252 | * Renders the editor containing the code that was the |
||
253 | * origin of the exception. |
||
254 | * |
||
255 | * @param \Whoops\Exception\Frame $frame |
||
256 | * |
||
257 | * @return \NunoMaduro\Collision\Contracts\Writer |
||
258 | */ |
||
259 | 4 | protected function renderEditor(Frame $frame): WriterContract |
|
269 | |||
270 | /** |
||
271 | * Renders the trace of the exception. |
||
272 | * |
||
273 | * @param array $frames |
||
274 | * |
||
275 | * @return \NunoMaduro\Collision\Contracts\Writer |
||
276 | */ |
||
277 | 4 | protected function renderTrace(array $frames): WriterContract |
|
299 | |||
300 | /** |
||
301 | * Renders an message into the console. |
||
302 | * |
||
303 | * @param string $message |
||
304 | * @param bool $break |
||
305 | * |
||
306 | * @return $this |
||
307 | */ |
||
308 | 5 | protected function render(string $message, bool $break = true): WriterContract |
|
318 | |||
319 | /** |
||
320 | * Formats a message as a block of text. |
||
321 | * |
||
322 | * @param string|array $messages The message to write in the block |
||
323 | * @param string|null $type The block type (added in [] on first line) |
||
324 | * @param string|null $style The style to apply to the whole block |
||
325 | * @param string $prefix The prefix for the block |
||
326 | * @param bool $padding Whether to add vertical padding |
||
327 | * @param bool $escape Whether to escape the message |
||
328 | */ |
||
329 | protected function block($messages, $type = null, $style = null, $prefix = ' ', $padding = false, $escape = true) |
||
337 | } |
||
338 |
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: