1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the Jira-CLI library. |
4
|
|
|
* For the full copyright and license information, please view |
5
|
|
|
* the LICENSE file that was distributed with this source code. |
6
|
|
|
* |
7
|
|
|
* @copyright Alexander Obuhovich <[email protected]> |
8
|
|
|
* @link https://github.com/console-helpers/jira-cli |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace ConsoleHelpers\JiraCLI\Command; |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
15
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
16
|
|
|
|
17
|
|
|
class VersionsCommand extends AbstractCommand |
18
|
|
|
{ |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* {@inheritdoc} |
22
|
|
|
*/ |
23
|
|
|
protected function configure() |
24
|
|
|
{ |
25
|
|
|
$this |
26
|
|
|
->setName('versions') |
27
|
|
|
->setDescription('Shows version usage across projects'); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* {@inheritdoc} |
32
|
|
|
*/ |
33
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
34
|
|
|
{ |
35
|
|
|
$versions = array(); |
36
|
|
|
|
37
|
|
|
$this->io->write('Getting projects ... '); |
38
|
|
|
$projects = $this->jiraApi->getProjects()->getResult(); |
39
|
|
|
$this->io->writeln('done (' . count($projects) . ' found)'); |
40
|
|
|
|
41
|
|
|
foreach ( $projects as $index => $project_data ) { |
42
|
|
|
$project_key = $project_data['key']; |
43
|
|
|
|
44
|
|
|
$this->io->write('Getting project <info>#' . $index . '</info> versions ... '); |
45
|
|
|
$project_versions = $this->jiraApi->getVersions($project_key); |
46
|
|
|
$this->io->writeln('done (' . count($project_versions) . ' found)'); |
47
|
|
|
|
48
|
|
|
foreach ( $project_versions as $project_version_data ) { |
|
|
|
|
49
|
|
|
$project_version = $project_version_data['name']; |
50
|
|
|
|
51
|
|
|
// Interested only in final releases. |
52
|
|
|
if ( strpos($project_version, '-') === false ) { |
53
|
|
|
$versions[$project_version] = true; |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
$versions = array_keys($versions); |
59
|
|
|
usort($versions, 'version_compare'); |
60
|
|
|
|
61
|
|
|
$this->io->writeln(array('', 'Versions:')); |
62
|
|
|
|
63
|
|
|
foreach ( $versions as $version ) { |
64
|
|
|
$this->io->writeln(' * ' . $version); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
} |
69
|
|
|
|
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.