VersionsCommand::execute()   A
last analyzed

Complexity

Conditions 5
Paths 8

Size

Total Lines 33
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 5
eloc 18
c 2
b 0
f 0
nc 8
nop 2
dl 0
loc 33
ccs 0
cts 19
cp 0
crap 30
rs 9.3554
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)');
0 ignored issues
show
Bug introduced by
It seems like $project_versions can also be of type false; however, parameter $value of count() does only seem to accept Countable|array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

45
			$this->io->writeln('done (' . count(/** @scrutinizer ignore-type */ $project_versions) . ' found)');
Loading history...
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
		$this->showStatistics();
67
	}
68
69
}
70