ListCommand::execute()   B
last analyzed

Complexity

Conditions 5
Paths 9

Size

Total Lines 32
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 32
rs 8.439
cc 5
eloc 22
nc 9
nop 2
1
<?php
2
3
namespace N98\Magento\Command\Customer;
4
5
use Symfony\Component\Console\Input\InputArgument;
6
use Symfony\Component\Console\Input\InputInterface;
7
use Symfony\Component\Console\Input\InputOption;
8
use Symfony\Component\Console\Output\OutputInterface;
9
use N98\Util\Console\Helper\Table\Renderer\RendererFactory;
10
11
class ListCommand extends AbstractCustomerCommand
12
{
13 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...
14
    {
15
        $this
16
            ->setName('customer:list')
17
            ->setDescription('Lists all magento customers')
18
            ->addArgument('search', InputArgument::OPTIONAL, 'Search query')
19
            ->addOption(
20
                'format',
21
                null,
22
                InputOption::VALUE_OPTIONAL,
23
                'Output Format. One of [' . implode(',', RendererFactory::getFormats()) . ']'
24
            );
25
26
        $help = <<<HELP
27
Lists all Magento Customers of current installation.
28
HELP;
29
        $this->setHelp($help);
30
    }
31
32
    /**
33
     * @param \Symfony\Component\Console\Input\InputInterface $input
34
     * @param \Symfony\Component\Console\Output\OutputInterface $output
35
     *
36
     * @return int|void
37
     */
38
    protected function execute(InputInterface $input, OutputInterface $output)
39
    {
40
        $this->detectMagento($output, true);
41
        if (!$this->initMagento()) {
42
            return;
43
        }
44
45
        $search = null;
46
        if ($input->getArgument('search')) {
47
            $search = $input->getArgument('search');
48
        }
49
50
        $table = [];
51
        foreach ($this->getCustomerList($search) as $index) {
52
            $table[] = [
53
                $index['id'],
54
                $index['firstname'],
55
                $index['lastname'],
56
                $index['email'],
57
                $index['website'],
58
                $index['created_at'],
59
            ];
60
        }
61
62
        if (count($table) > 0) {
63
            $helper = $this->getHelper('table');
64
            $helper->setHeaders(['id', 'email', 'firstname', 'lastname', 'website', 'created_at']);
65
            $helper->renderByFormat($output, $table, $input->getOption('format'));
66
        } else {
67
            $output->writeln('<comment>No customers found</comment>');
68
        }
69
    }
70
}
71