1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* ListCommand.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
|
|
|
namespace IPub\Packages\Commands; |
18
|
|
|
|
19
|
|
|
use Symfony\Component\Console\Input; |
20
|
|
|
use Symfony\Component\Console\Output; |
21
|
|
|
|
22
|
|
|
use IPub\Packages\Exceptions; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* List packages command |
26
|
|
|
* |
27
|
|
|
* @package iPublikuj:Packages! |
28
|
|
|
* @subpackage Commands |
29
|
|
|
* |
30
|
|
|
* @author Josef Kříž <[email protected]> |
31
|
|
|
* @author Adam Kadlec <[email protected]> |
32
|
|
|
*/ |
33
|
1 |
|
final class ListCommand extends Command |
34
|
|
|
{ |
35
|
|
|
/** |
36
|
|
|
* @return void |
37
|
|
|
*/ |
38
|
|
|
protected function configure() : void |
39
|
|
|
{ |
40
|
|
|
$this |
41
|
|
|
->setName('ipub:packages:list') |
42
|
|
|
->setDescription('List of installed packages.'); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @param Input\InputInterface $input |
47
|
|
|
* @param Output\OutputInterface $output |
48
|
|
|
* |
49
|
|
|
* @return void |
50
|
|
|
*/ |
51
|
|
|
protected function execute(Input\InputInterface $input, Output\OutputInterface $output) : void |
52
|
|
|
{ |
53
|
|
|
// Register available |
54
|
|
View Code Duplication |
foreach ($this->packageManager->registerAvailable() as $item) { |
|
|
|
|
55
|
|
|
foreach ($item as $name => $action) { |
56
|
|
|
$output->writeln(sprintf('<info>%s : %s</info>', $action, $name)); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
try { |
61
|
|
|
$packages = $this->repository->getPackages(); |
62
|
|
|
|
63
|
|
|
$maxLength = 0; |
64
|
|
|
|
65
|
|
|
foreach ($packages as $package) { |
66
|
|
|
$length = strlen($package->getName()); |
67
|
|
|
|
68
|
|
|
$maxLength = $maxLength > $length ? $maxLength : $length; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
foreach ($packages as $package) { |
72
|
|
|
$output->writeln(sprintf( |
73
|
|
|
'<info>%' . $maxLength . 's</info> | status: <comment>%-12s</comment> | version: <comment>%s</comment>', |
74
|
|
|
$package->getName(), |
75
|
|
|
$this->packageManager->getStatus($package), |
76
|
|
|
$this->packageManager->getVersion($package) |
77
|
|
|
)); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
} catch (Exceptions\InvalidArgumentException $e) { |
81
|
|
|
$output->writeln(sprintf('<error>%s</error>', $e->getMessage())); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
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.