1 | <?php |
||
26 | class GenerateVersionsCommand extends Command |
||
27 | { |
||
28 | /** |
||
29 | * @var string |
||
30 | */ |
||
31 | private $composerCmd; |
||
32 | |||
33 | /** |
||
34 | * @var string |
||
35 | */ |
||
36 | private $gitCmd; |
||
37 | |||
38 | /** |
||
39 | * @var string |
||
40 | */ |
||
41 | private $contextDir; |
||
42 | |||
43 | /* |
||
44 | * @var \Symfony\Component\Console\Output\OutputInterface |
||
45 | */ |
||
46 | private $output; |
||
47 | |||
48 | /** |
||
49 | * {@inheritDoc} |
||
50 | * |
||
51 | * @return void |
||
52 | */ |
||
53 | 4 | protected function configure() |
|
62 | |||
63 | /** |
||
64 | * {@inheritDoc} |
||
65 | * |
||
66 | * @param InputInterface $input input |
||
67 | * @param OutputInterface $output output |
||
68 | * |
||
69 | * @return void |
||
70 | */ |
||
71 | 2 | protected function execute(InputInterface $input, OutputInterface $output) |
|
88 | |||
89 | /** |
||
90 | * gets all versions |
||
91 | * |
||
92 | * @return array version numbers of packages |
||
93 | */ |
||
94 | 2 | public function getPackageVersions() |
|
108 | |||
109 | /** |
||
110 | * returns the version of graviton or wrapper (the context) using git |
||
111 | * |
||
112 | * @return array |
||
113 | * |
||
114 | * @throws CommandNotFoundException |
||
115 | */ |
||
116 | 2 | private function getContextVersion() |
|
138 | |||
139 | /** |
||
140 | * returns version for every installed package |
||
141 | * |
||
142 | * @param array $versions versions array |
||
143 | * @return array |
||
144 | */ |
||
145 | 2 | private function getInstalledPackagesVersion($versions) |
|
167 | |||
168 | /** |
||
169 | * runs a composer command depending on the context |
||
170 | * |
||
171 | * @param string $command composer args |
||
172 | * @return string |
||
173 | * |
||
174 | * @throws \RuntimeException |
||
175 | */ |
||
176 | 2 | private function runComposerInContext($command) |
|
190 | |||
191 | /** |
||
192 | * Checks if a command is available in an enviroment and in the context. The command might be as well a path |
||
193 | * to a command. |
||
194 | * |
||
195 | * @param String $command the command to be checked for availability |
||
196 | * @return bool |
||
197 | */ |
||
198 | 2 | private function commandAvailable($command) |
|
207 | |||
208 | |||
209 | /** |
||
210 | * runs a git command depending on the context |
||
211 | * |
||
212 | * @param string $command git args |
||
213 | * @return string |
||
214 | * |
||
215 | * @throws \RuntimeException |
||
216 | */ |
||
217 | 2 | private function runGitInContext($command) |
|
231 | |||
232 | /** |
||
233 | * checks if the package version is configured |
||
234 | * |
||
235 | * @param string $packageName package name |
||
236 | * @return boolean |
||
237 | * |
||
238 | * @throws \RuntimeException |
||
239 | */ |
||
240 | 2 | private function isDesiredVersion($packageName) |
|
258 | |||
259 | /** |
||
260 | * reads configuration information from the given file into an array. |
||
261 | * |
||
262 | * @param string $filePath Absolute path to the configuration file. |
||
263 | * |
||
264 | * @return array |
||
265 | */ |
||
266 | 2 | private function getConfiguration($filePath) |
|
273 | |||
274 | /** |
||
275 | * Returns the version out of a given version string |
||
276 | * |
||
277 | * @param string $versionString SemVer version string |
||
278 | * @return string |
||
279 | */ |
||
280 | public function getVersionNumber($versionString) |
||
290 | |||
291 | /** |
||
292 | * Get a version string string using a regular expression |
||
293 | * |
||
294 | * @param string $versionString SemVer version string |
||
295 | * @return string |
||
296 | */ |
||
297 | private function getVersionOrBranchName($versionString) |
||
314 | |||
315 | /** |
||
316 | * Normalizing the incorrect SemVer string to a valid one |
||
317 | * |
||
318 | * At the moment, we are getting the version of the root package ('self') using the |
||
319 | * 'composer show -s'-command. Unfortunately Composer is adding an unnecessary ending. |
||
320 | * |
||
321 | * @param string $versionString SemVer version string |
||
322 | * @param string $prefix Version prefix |
||
323 | * @return string |
||
324 | */ |
||
325 | private function normalizeVersionString($versionString, $prefix = 'v') |
||
336 | } |
||
337 |
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 sub-classes 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 parent class: