1 | <?php |
||
11 | class Command extends ContainerAwareCommand |
||
12 | { |
||
13 | private $progress; |
||
14 | |||
15 | /** |
||
16 | * Initialise the progress bar |
||
17 | * @param OutputInterface $output The output |
||
18 | * @param int $count The number of steps |
||
19 | * @return void |
||
20 | */ |
||
21 | protected function initProgress($output, $count) |
||
28 | |||
29 | /** |
||
30 | * Advance the progress bar a step forward |
||
31 | * @return void |
||
32 | */ |
||
33 | protected function advance() |
||
41 | |||
42 | /** |
||
43 | * Mark the progress bar as finished |
||
44 | * @return void |
||
45 | */ |
||
46 | protected function finishProgress() |
||
54 | |||
55 | protected function clearCache($output) |
||
67 | |||
68 | /** |
||
69 | * Return a function that can be used by Symfony's process to show the output |
||
70 | * of a process live on our screen |
||
71 | * |
||
72 | * @param OutputInterface $output The console output |
||
73 | * |
||
74 | * @return null|\Closure |
||
75 | */ |
||
76 | protected function getBufferFunction($output) |
||
90 | } |
||
91 |
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: