Completed
Push — master ( 2454a8...540363 )
by Tom
15:51
created

ListCommand::findInstalledModules()   B

Complexity

Conditions 5
Paths 9

Size

Total Lines 20
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 6
Bugs 1 Features 0
Metric Value
c 6
b 1
f 0
dl 0
loc 20
rs 8.8571
cc 5
eloc 13
nc 9
nop 0
1
<?php
2
3
namespace N98\Magento\Command\Developer\Module;
4
5
use N98\Magento\Command\AbstractMagentoCommand;
6
use N98\Magento\Modules;
7
use N98\Util\Console\Helper\Table\Renderer\RendererFactory;
8
use N98\Util\Console\Helper\TableHelper;
9
use Symfony\Component\Console\Input\InputInterface;
10
use Symfony\Component\Console\Input\InputOption;
11
use Symfony\Component\Console\Output\OutputInterface;
12
13
class ListCommand extends AbstractMagentoCommand
14
{
15 View Code Duplication
    protected function configure()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
16
    {
17
        $this
18
            ->setName('dev:module:list')
19
            ->addOption('codepool', null, InputOption::VALUE_OPTIONAL, 'Show modules in a specific codepool')
20
            ->addOption('status', null, InputOption::VALUE_OPTIONAL, 'Show modules with a specific status')
21
            ->addOption('vendor', null, InputOption::VALUE_OPTIONAL, 'Show modules of a specified vendor')
22
            ->setAliases(array('sys:modules:list'))// deprecated
23
            ->setDescription('List all installed modules')
24
            ->addOption(
25
                'format',
26
                null,
27
                InputOption::VALUE_OPTIONAL,
28
                'Output Format. One of [' . implode(',', RendererFactory::getFormats()) . ']'
29
            );
30
    }
31
32
    /**
33
     * @param InputInterface $input
34
     * @param OutputInterface $output
35
     *
36
     * @return int|void
37
     */
38
    protected function execute(InputInterface $input, OutputInterface $output)
39
    {
40
        $this->detectMagento($output, true);
41
42
        if ($input->getOption('format') === null) {
43
            $this->writeSection($output, 'Magento Modules');
44
        }
45
        $this->initMagento();
46
47
        $modules = $this->filterModules($input);
48
49
        if (!count($modules)) {
50
            $output->writeln("No modules match the specified criteria.");
51
            return;
52
        }
53
54
        /** @var TableHelper $table */
55
        $table = $this->getHelper('table');
56
        $table
57
            ->setHeaders(array('codePool', 'Name', 'Version', 'Status'))
58
            ->renderByFormat($output, iterator_to_array($modules), $input->getOption('format'));
59
    }
60
61
    /**
62
     * @param InputInterface $input
63
     *
64
     * @return Modules
65
     */
66
    private function filterModules(InputInterface $input)
67
    {
68
        $modules = new Modules();
69
        $modules = $modules->findInstalledModules()
70
            ->filterModules($input);
71
72
        return $modules;
73
    }
74
}
75