SyncCommand   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 52
Duplicated Lines 9.62 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 5.56%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 3
dl 5
loc 52
ccs 1
cts 18
cp 0.0556
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 7 1
B execute() 5 32 7

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
			/*
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