Completed
Push — develop ( 73bd0a...ccb498 )
by Tom
05:04
created

ModulesCommand   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 3
c 2
b 0
f 1
lcom 0
cbo 3
dl 0
loc 32
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 7 1
A execute() 0 15 2
1
<?php
2
3
namespace N98\Magento\Command\Developer\Console;
4
5
use Magento\Framework\Module\ModuleListInterface;
6
use N98\Util\BinaryString;
7
use Symfony\Component\Console\Input\InputArgument;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Output\OutputInterface;
10
11
class ModulesCommand extends AbstractConsoleCommand
12
{
13
    protected function configure()
14
    {
15
        $this
16
            ->setName('modules')
17
            ->addArgument('vendor', InputArgument::OPTIONAL, 'Vendor to filter', '')
18
            ->setDescription('List all modules');
19
    }
20
21
    /**
22
     * @param InputInterface $input
23
     * @param OutputInterface $output
24
     *
25
     * @return int|void
26
     */
27
    protected function execute(InputInterface $input, OutputInterface $output)
28
    {
29
        $moduleList = $this->create(ModuleListInterface::class);
30
31
        $modules = array_keys($moduleList->getAll());
32
33
        $vendorArgument = $input->getArgument('vendor');
34
        if ($vendorArgument !== '') {
35
            $modules = array_filter($modules, function ($module) use ($vendorArgument) {
36
                return BinaryString::startsWith($module, ucfirst($vendorArgument));
37
            });
38
        }
39
40
        $output->writeln('<strong>' . implode(PHP_EOL, $modules) . '</strong>');
41
    }
42
}
43