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 | * @var \Symfony\Component\Filesystem\Filesystem |
||
50 | */ |
||
51 | private $filesystem; |
||
52 | |||
53 | /* |
||
54 | * @var |Symfony\Component\Yaml\Dumper |
||
55 | */ |
||
56 | private $dumper; |
||
57 | |||
58 | /* |
||
59 | * @var |Symfony\Component\Yaml\Parser |
||
60 | */ |
||
61 | private $parser; |
||
62 | |||
63 | /** |
||
64 | * {@inheritDoc} |
||
65 | * |
||
66 | * @return void |
||
67 | */ |
||
68 | 4 | protected function configure() |
|
69 | { |
||
70 | 4 | parent::configure(); |
|
71 | |||
72 | 4 | $this->setName('graviton:core:generateversions') |
|
73 | 4 | ->setDescription( |
|
74 | 4 | 'Generates the versions.yml file according to definition in app/config/version_service.yml' |
|
75 | ); |
||
76 | 4 | } |
|
77 | |||
78 | |||
79 | /** |
||
80 | * set filesystem (in service-definition) |
||
81 | * |
||
82 | * @param \Symfony\Component\Filesystem\Filesystem $filesystem filesystem |
||
83 | * |
||
84 | * @return void |
||
85 | */ |
||
86 | 4 | public function setFilesystem(Filesystem $filesystem) |
|
90 | |||
91 | /** |
||
92 | * set dumper (in service-definition) |
||
93 | * |
||
94 | * @param \Symfony\Component\Yaml\Dumper $dumper dumper |
||
95 | * |
||
96 | * @return void |
||
97 | */ |
||
98 | 4 | public function setDumper(Dumper $dumper) |
|
102 | |||
103 | /** |
||
104 | * set parser (in service-definition) |
||
105 | * |
||
106 | * @param \Symfony\Component\Yaml\Parser $parser parser |
||
107 | * |
||
108 | * @return void |
||
109 | */ |
||
110 | 4 | public function setParser(Parser $parser) |
|
114 | |||
115 | /** |
||
116 | * {@inheritDoc} |
||
117 | * |
||
118 | * @param InputInterface $input input |
||
119 | * @param OutputInterface $output output |
||
120 | * |
||
121 | * @return void |
||
122 | */ |
||
123 | 2 | protected function execute(InputInterface $input, OutputInterface $output) |
|
139 | |||
140 | /** |
||
141 | * gets all versions |
||
142 | * |
||
143 | * @return array version numbers of packages |
||
144 | */ |
||
145 | 2 | public function getPackageVersions() |
|
158 | |||
159 | /** |
||
160 | * returns the version of graviton or wrapper (the context) using git |
||
161 | * |
||
162 | * @return array |
||
163 | * |
||
164 | * @throws CommandNotFoundException |
||
165 | */ |
||
166 | 2 | private function getContextVersion() |
|
188 | |||
189 | /** |
||
190 | * returns version for every installed package |
||
191 | * |
||
192 | * @param array $versions versions array |
||
193 | * @throws CommandNotFoundException | \RuntimeException |
||
194 | * @return array |
||
195 | */ |
||
196 | 2 | private function getInstalledPackagesVersion($versions) |
|
216 | |||
217 | /** |
||
218 | * runs a command depending on the context |
||
219 | * |
||
220 | * @param string $command in this case composer or git |
||
221 | * @return string |
||
222 | * |
||
223 | * @throws \RuntimeException |
||
224 | */ |
||
225 | 2 | private function runCommandInContext($command) |
|
238 | |||
239 | /** |
||
240 | * Checks if a command is available in an enviroment and in the context. The command might be as well a path |
||
241 | * to a command. |
||
242 | * |
||
243 | * @param String $command the command to be checked for availability |
||
244 | * @return bool |
||
245 | */ |
||
246 | 2 | private function commandAvailable($command) |
|
255 | |||
256 | /** |
||
257 | * checks if the package version is configured |
||
258 | * |
||
259 | * @param string $packageName package name |
||
260 | * @return boolean |
||
261 | * |
||
262 | * @throws \RuntimeException |
||
263 | */ |
||
264 | 2 | private function isDesiredVersion($packageName) |
|
282 | |||
283 | /** |
||
284 | * reads configuration information from the given file into an array. |
||
285 | * |
||
286 | * @param string $filePath Absolute path to the configuration file. |
||
287 | * |
||
288 | * @return array |
||
289 | */ |
||
290 | 2 | private function getConfiguration($filePath) |
|
296 | |||
297 | /** |
||
298 | * Returns the version out of a given version string |
||
299 | * |
||
300 | * @param string $versionString SemVer version string |
||
301 | * @return string |
||
302 | */ |
||
303 | public function getVersionNumber($versionString) |
||
313 | |||
314 | /** |
||
315 | * Get a version string string using a regular expression |
||
316 | * |
||
317 | * @param string $versionString SemVer version string |
||
318 | * @return string |
||
319 | */ |
||
320 | private function getVersionOrBranchName($versionString) |
||
337 | |||
338 | /** |
||
339 | * Normalizing the incorrect SemVer string to a valid one |
||
340 | * |
||
341 | * At the moment, we are getting the version of the root package ('self') using the |
||
342 | * 'composer show -s'-command. Unfortunately Composer is adding an unnecessary ending. |
||
343 | * |
||
344 | * @param string $versionString SemVer version string |
||
345 | * @param string $prefix Version prefix |
||
346 | * @return string |
||
347 | */ |
||
348 | private function normalizeVersionString($versionString, $prefix = 'v') |
||
359 | } |
||
360 |
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: