Passed
Push — master ( 6791f9...01e57e )
by Adam
02:08
created

SyncCommand   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 4.76%

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 3
dl 0
loc 52
ccs 1
cts 21
cp 0.0476
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 7 1
D execute() 0 32 9
1
<?php
2
/**
3
 * SyncCommand.php
4
 *
5
 * @copyright      More in license.md
6
 * @license        https://www.ipublikuj.eu
7
 * @author         Adam Kadlec https://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
18
namespace IPub\Packages\Commands;
19
20
use Symfony\Component\Console\Input;
21
use Symfony\Component\Console\Output;
22
23
use IPub\Packages\DependencyResolver;
24
use IPub\Packages\Exceptions;
25
26
/**
27
 * Synchronize packages command
28
 *
29
 * @package        iPublikuj:Packages!
30
 * @subpackage     Commands
31
 *
32
 * @author         Josef Kříž <[email protected]>
33
 * @author         Adam Kadlec <[email protected]>
34
 */
35 1
class SyncCommand extends Command
36
{
37
	/**
38
	 * @return void
39
	 */
40
	protected function configure() : void
41
	{
42
		$this
43
			->setName('ipub:packages:sync')
44
			->addOption('composer', NULL, Input\InputOption::VALUE_NONE, 'run as composer script')
45
			->setDescription('Synchronize 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) : void
55
	{
56
		if ($input->getOption('composer')) {
57
			$output->writeln('+---------------------------------+');
58
			$output->writeln('| Package manager synchronization |');
59
			$output->writeln('+---------------------------------+');
60
		}
61
62
		// Register available
63
		foreach ($this->packageManager->registerAvailable() as $item) {
64
			foreach ($item as $name => $action) {
65
				$output->writeln(sprintf('<info>%s : %s</info>', $action, $name));
66
			}
67
		}
68
69
		try {
70
			foreach ($this->packageManager->enableAvailable() as $item) {
71
				foreach ($item as $name => $action) {
72
					$output->writeln(sprintf('<info>%s : %s</info>', $action, $name));
73
				}
74
			}
75
76
			foreach ($this->packageManager->disableAbsent() as $item) {
77
				foreach ($item as $name => $action) {
78
					$output->writeln(sprintf('<info>%s : %s</info>', $action, $name));
79
				}
80
			}
81
82
		} catch (Exceptions\InvalidArgumentException $e) {
83
			$output->writeln(sprintf('<error>%s</error>', $e->getMessage()));
84
		}
85
	}
86
}
87