Completed
Push — master ( 60e59a...334051 )
by Adam
06:35
created

SyncCommand::execute()   D

Complexity

Conditions 9
Paths 168

Size

Total Lines 32
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 32
rs 4.6666
cc 9
eloc 17
nc 168
nop 2
1
<?php
2
/**
3
 * SyncCommand.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
18
namespace IPub\Packages\Commands;
19
20
use Symfony\Component\Console\Input;
21
use Symfony\Component\Console\Output;
22
23
use IPub;
24
use IPub\Packages;
25
use IPub\Packages\DependencyResolver;
26
use IPub\Packages\Exceptions;
27
28
/**
29
 * Synchronize packages command
30
 *
31
 * @package        iPublikuj:Packages!
32
 * @subpackage     Commands
33
 *
34
 * @author         Josef Kříž <[email protected]>
35
 * @author         Adam Kadlec <[email protected]>
36
 */
37
class SyncCommand extends Command
38
{
39
	/**
40
	 * @return void
41
	 */
42
	protected function configure()
43
	{
44
		$this
45
			->setName('ipub:packages:sync')
46
			->addOption('composer', NULL, Input\InputOption::VALUE_NONE, 'run as composer script')
47
			->setDescription('Synchronize packages.');
48
	}
49
50
	/**
51
	 * @param Input\InputInterface $input
52
	 * @param Output\OutputInterface $output
53
	 *
54
	 * @return void
55
	 */
56
	protected function execute(Input\InputInterface $input, Output\OutputInterface $output)
57
	{
58
		if ($input->getOption('composer')) {
59
			$output->writeln('+---------------------------------+');
60
			$output->writeln('| Package manager synchronization |');
61
			$output->writeln('+---------------------------------+');
62
		}
63
64
		// Register available
65
		foreach ($this->packageManager->registerAvailable() as $item) {
66
			foreach ($item as $name => $action) {
0 ignored issues
show
Bug introduced by
The expression $item of type string is not traversable.
Loading history...
67
				$output->writeln(sprintf('<info>%s : %s</info>', $action, $name));
68
			}
69
		}
70
71
		try {
72
			foreach ($this->packageManager->enableAvailable() as $item) {
73
				foreach ($item as $name => $action) {
0 ignored issues
show
Bug introduced by
The expression $item of type string is not traversable.
Loading history...
74
					$output->writeln(sprintf('<info>%s : %s</info>', $action, $name));
75
				}
76
			}
77
78
			foreach ($this->packageManager->disableAbsent() as $item) {
79
				foreach ($item as $name => $action) {
0 ignored issues
show
Bug introduced by
The expression $item of type string is not traversable.
Loading history...
80
					$output->writeln(sprintf('<info>%s : %s</info>', $action, $name));
81
				}
82
			}
83
84
		} catch (Exceptions\InvalidArgumentException $e) {
85
			$output->writeln(sprintf('<error>%s</error>', $e->getMessage()));
86
		}
87
	}
88
}
89