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) { |
|
|
|
|
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
|
|
|
|
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.