/
ShowCommand.php
96 lines (81 loc) · 2.72 KB
/
ShowCommand.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
namespace Psalm\Internal\PluginManager\Command;
use Psalm\Internal\PluginManager\PluginListFactory;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use UnexpectedValueException;
use function array_keys;
use function array_map;
use function array_values;
use function count;
use function getcwd;
use function is_string;
use const DIRECTORY_SEPARATOR;
/**
* @internal
*/
class ShowCommand extends Command
{
/** @var PluginListFactory */
private $plugin_list_factory;
public function __construct(PluginListFactory $plugin_list_factory)
{
$this->plugin_list_factory = $plugin_list_factory;
parent::__construct();
}
protected function configure(): void
{
$this
->setName('show')
->setDescription('Lists enabled and available plugins')
->addOption('config', 'c', InputOption::VALUE_REQUIRED, 'Path to Psalm config file')
->addUsage('[-c path/to/psalm.xml]');
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
$current_dir = (string) getcwd() . DIRECTORY_SEPARATOR;
$config_file_path = $input->getOption('config');
if ($config_file_path !== null && !is_string($config_file_path)) {
throw new UnexpectedValueException('Config file path should be a string');
}
$plugin_list = ($this->plugin_list_factory)($current_dir, $config_file_path);
$enabled = $plugin_list->getEnabled();
$available = $plugin_list->getAvailable();
$formatRow =
/**
* @return array{0: null|string, 1: string}
*/
static fn(string $class, ?string $package): array => [$package, $class];
$io->section('Enabled');
if (count($enabled)) {
$io->table(
['Package', 'Class'],
array_map(
$formatRow,
array_keys($enabled),
array_values($enabled)
)
);
} else {
$io->note('No plugins enabled');
}
$io->section('Available');
if (count($available)) {
$io->table(
['Package', 'Class'],
array_map(
$formatRow,
array_keys($available),
array_values($available)
)
);
} else {
$io->note('No plugins available');
}
return 0;
}
}