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

SyncCommand::execute()   D

Complexity

Conditions 9
Paths 168

Size

Total Lines 32
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 90

Importance

Changes 0
Metric Value
dl 0
loc 32
ccs 0
cts 16
cp 0
rs 4.6666
c 0
b 0
f 0
cc 9
eloc 17
nc 168
nop 2
crap 90
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