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 ConsoleHelpers\JiraCLI\JiraApi; |
15
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
16
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
17
|
|
|
|
18
|
|
|
class VersionsCommand extends AbstractCommand |
19
|
|
|
{ |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* {@inheritdoc} |
23
|
|
|
*/ |
24
|
|
|
protected function configure() |
25
|
|
|
{ |
26
|
|
|
$this |
27
|
|
|
->setName('versions') |
28
|
|
|
->setDescription('Shows version usage across projects'); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* {@inheritdoc} |
33
|
|
|
*/ |
34
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
35
|
|
|
{ |
36
|
|
|
$versions = array(); |
37
|
|
|
|
38
|
|
|
$this->io->write('Getting projects ... '); |
39
|
|
|
$project_keys = $this->jiraApi->getProjectKeys(); |
40
|
|
|
$this->io->writeln('done (' . count($project_keys) . ' found)'); |
41
|
|
|
|
42
|
|
|
foreach ( $project_keys as $project_key ) { |
43
|
|
|
$this->io->write('Getting project <info>' . $project_key . '</info> versions ... '); |
44
|
|
|
$project_versions = $this->jiraApi->getVersions($project_key, JiraApi::CACHE_DURATION_ONE_MONTH); |
45
|
|
|
$this->io->writeln('done (' . count($project_versions) . ' found)'); |
46
|
|
|
|
47
|
|
|
foreach ( $project_versions as $project_version_data ) { |
|
|
|
|
48
|
|
|
$project_version = $project_version_data['name']; |
49
|
|
|
|
50
|
|
|
// Interested only in final releases. |
51
|
|
|
if ( strpos($project_version, '-') === false ) { |
52
|
|
|
$versions[$project_version] = true; |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
$versions = array_keys($versions); |
58
|
|
|
usort($versions, 'version_compare'); |
59
|
|
|
|
60
|
|
|
$this->io->writeln(array('', 'Versions:')); |
61
|
|
|
|
62
|
|
|
foreach ( $versions as $version ) { |
63
|
|
|
$this->io->writeln(' * ' . $version); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
} |
68
|
|
|
|
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.