Completed
Push — master ( 665429...116aa7 )
by Adam
07:10
created

ListCommand   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 9.09%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 6
dl 0
loc 52
ccs 2
cts 22
cp 0.0909
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 6 1
C execute() 0 33 7
1
<?php
2
/**
3
 * ListCommand.php
4
 *
5
 * @copyright      More in license.md
6
 * @license        http://www.ipublikuj.eu
7
 * @author         Adam Kadlec http://www.ipublikuj.eu
8
 * @package        iPublikuj:Packages!
9
 * @subpackage     Commands
10
 * @since          2.0.0
11
 *
12
 * @date           19.07.16
13
 */
14
15
declare(strict_types = 1);
16
17
namespace IPub\Packages\Commands;
18
19
use Symfony\Component\Console\Input;
20
use Symfony\Component\Console\Output;
21
22
use IPub;
23
use IPub\Packages;
24
use IPub\Packages\DependencyResolver;
25
use IPub\Packages\Exceptions;
26
27
/**
28
 * List packages command
29
 *
30
 * @package        iPublikuj:Packages!
31
 * @subpackage     Commands
32
 *
33
 * @author         Josef Kříž <[email protected]>
34
 * @author         Adam Kadlec <[email protected]>
35
 */
36 1
final class ListCommand extends Command
37
{
38
	/**
39
	 * @return void
40
	 */
41
	protected function configure()
42
	{
43
		$this
44
			->setName('ipub:packages:list')
45
			->setDescription('List of installed packages.');
46
	}
47
48
	/**
49
	 * @param Input\InputInterface $input
50
	 * @param Output\OutputInterface $output
51
	 *
52
	 * @return void
53
	 */
54
	protected function execute(Input\InputInterface $input, Output\OutputInterface $output)
55
	{
56
		// Register available
57
		foreach ($this->packageManager->registerAvailable() as $item) {
58
			foreach ($item as $name => $action) {
59
				$output->writeln(sprintf('<info>%s : %s</info>', $action, $name));
60
			}
61
		}
62
63
		try {
64
			$packages = $this->repository->getPackages();
65
66
			$maxLength = 0;
67
68
			foreach ($packages as $package) {
69
				$length = strlen($package->getName());
70
71
				$maxLength = $maxLength > $length ? $maxLength : $length;
72
			}
73
74
			foreach ($packages as $package) {
75
				$output->writeln(sprintf(
76
					'<info>%'. $maxLength .'s</info> | status: <comment>%-12s</comment> | version: <comment>%s</comment>',
77
					$package->getName(),
78
					$this->packageManager->getStatus($package),
79
					$this->packageManager->getVersion($package)
80
				));
81
			}
82
83
		} catch (Exceptions\InvalidArgumentException $e) {
84
			$output->writeln(sprintf('<error>%s</error>', $e->getMessage()));
85
		}
86
	}
87
}
88