1 | <?php |
||
43 | abstract class AbstractCommand extends Command |
||
44 | { |
||
45 | /** |
||
46 | * The configuration property only contains the configuration injected by the setter. |
||
47 | * |
||
48 | * @var Configuration |
||
49 | */ |
||
50 | private $configuration; |
||
51 | |||
52 | /** |
||
53 | * The migrationConfiguration property contains the configuration |
||
54 | * created taking into account the command line options. |
||
55 | * |
||
56 | * @var Configuration |
||
57 | */ |
||
58 | private $migrationConfiguration; |
||
59 | |||
60 | /** |
||
61 | * @var OutputWriter |
||
62 | */ |
||
63 | private $outputWriter; |
||
64 | |||
65 | /** |
||
66 | * @var \Doctrine\DBAL\Connection |
||
67 | */ |
||
68 | private $connection; |
||
69 | |||
70 | 50 | protected function configure() |
|
75 | |||
76 | 11 | protected function outputHeader(Configuration $configuration, OutputInterface $output) |
|
86 | |||
87 | 21 | public function setMigrationConfiguration(Configuration $config) |
|
91 | |||
92 | /** |
||
93 | * When any (config) command line option is passed to the migration the migrationConfiguration |
||
94 | * property is set with the new generated configuration. |
||
95 | * If no (config) option is passed the migrationConfiguration property is set to the value |
||
96 | * of the configuration one (if any). |
||
97 | * Else a new configuration is created and assigned to the migrationConfiguration property. |
||
98 | * |
||
99 | * @param InputInterface $input |
||
100 | * @param OutputInterface $output |
||
101 | * |
||
102 | * @return Configuration |
||
103 | */ |
||
104 | 34 | protected function getMigrationConfiguration(InputInterface $input, OutputInterface $output) |
|
118 | |||
119 | /** |
||
120 | * This method ensure that we stay compatible with symfony console 2.3 by using the deprecated dialog helper |
||
121 | * but use the ConfirmationQuestion when available. |
||
122 | * |
||
123 | * @param $question |
||
124 | * @param InputInterface $input |
||
125 | * @param OutputInterface $output |
||
126 | * @return mixed |
||
127 | */ |
||
128 | 6 | protected function askConfirmation($question, InputInterface $input, OutputInterface $output) |
|
129 | { |
||
130 | 6 | if (!$this->getHelperSet()->has('question')) { |
|
131 | 1 | return $this->getHelper('dialog')->askConfirmation($output, '<question>' . $question . '</question>', false); |
|
|
|||
132 | } |
||
133 | |||
134 | 6 | return $this->getHelper('question')->ask($input, $output, new ConfirmationQuestion($question)); |
|
135 | } |
||
136 | |||
137 | /** |
||
138 | * @param \Symfony\Component\Console\Output\OutputInterface $output |
||
139 | * |
||
140 | * @return \Doctrine\DBAL\Migrations\OutputWriter |
||
141 | */ |
||
142 | 33 | private function getOutputWriter(OutputInterface $output) |
|
152 | |||
153 | /** |
||
154 | * @param \Symfony\Component\Console\Input\InputInterface $input |
||
155 | * |
||
156 | * @return \Doctrine\DBAL\Connection |
||
157 | * @throws \Doctrine\DBAL\DBALException |
||
158 | */ |
||
159 | 33 | private function getConnection(InputInterface $input) |
|
181 | |||
182 | } |
||
183 |
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: