Completed
Push — master ( 51fd63...e659d7 )
by Adam
02:33
created

SyncCommand::execute()   C

Complexity

Conditions 7
Paths 42

Size

Total Lines 32
Code Lines 14

Duplication

Lines 5
Ratio 15.63 %

Code Coverage

Tests 0
CRAP Score 56

Importance

Changes 0
Metric Value
dl 5
loc 32
ccs 0
cts 13
cp 0
rs 6.7272
c 0
b 0
f 0
cc 7
eloc 14
nc 42
nop 2
crap 56
1
<?php
2
/**
3
 * SyncCommand.php
4
 *
5
 * @copyright      More in license.md
6
 * @license        https://www.ipublikuj.eu
7
 * @author         Adam Kadlec <[email protected]>
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\Exceptions;
24
25
/**
26
 * Synchronize packages command
27
 *
28
 * @package        iPublikuj:Packages!
29
 * @subpackage     Commands
30
 *
31
 * @author         Josef Kříž <[email protected]>
32
 * @author         Adam Kadlec <[email protected]>
33
 */
34 1
class SyncCommand extends Command
35
{
36
	/**
37
	 * @return void
38
	 */
39
	protected function configure() : void
40
	{
41
		$this
42
			->setName('ipub:packages:sync')
43
			->addOption('composer', NULL, Input\InputOption::VALUE_NONE, 'run as composer script')
44
			->setDescription('Synchronize packages.');
45
	}
46
47
	/**
48
	 * @param Input\InputInterface $input
49
	 * @param Output\OutputInterface $output
50
	 *
51
	 * @return void
52
	 */
53
	protected function execute(Input\InputInterface $input, Output\OutputInterface $output) : void
54
	{
55
		if ($input->getOption('composer') === FALSE) {
56
			$output->writeln('+---------------------------------+');
57
			$output->writeln('| Package manager synchronization |');
58
			$output->writeln('+---------------------------------+');
59
		}
60
61
		// Register available
62 View Code Duplication
		foreach ($this->packageManager->registerAvailable() as $item) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
63
			foreach ($item as $name => $action) {
64
				$output->writeln(sprintf('<info>%s : %s</info>', $action, $name));
65
			}
66
		}
67
68
		try {
69
			foreach ($this->packageManager->enableAvailable() as $item) {
70
				foreach ($item as $name => $action) {
71
					$output->writeln(sprintf('<info>%s : %s</info>', $action, $name));
72
				}
73
			}
74
/*
0 ignored issues
show
Unused Code Comprehensibility introduced by
62% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
75
			foreach ($this->packageManager->disableAbsent() as $item) {
76
				foreach ($item as $name => $action) {
77
					$output->writeln(sprintf('<info>%s : %s</info>', $action, $name));
78
				}
79
			}
80
*/
81
		} catch (Exceptions\InvalidArgumentException $e) {
82
			$output->writeln(sprintf('<error>%s</error>', $e->getMessage()));
83
		}
84
	}
85
}
86