TemplatesCommand::main()   B
last analyzed

Complexity

Conditions 4
Paths 2

Size

Total Lines 79

Duplication

Lines 30
Ratio 37.97 %

Importance

Changes 0
Metric Value
dl 30
loc 79
rs 8.4581
c 0
b 0
f 0
cc 4
nc 2
nop 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/*
4
 * This file is part of gpupo/netshoes-sdk
5
 * Created by Gilmar Pupo <[email protected]>
6
 * For the information of copyright and license you should read the file
7
 * LICENSE which is distributed with this source code.
8
 * Para a informação dos direitos autorais e de licença você deve ler o arquivo
9
 * LICENSE que é distribuído com este código-fonte.
10
 * Para obtener la información de los derechos de autor y la licencia debe leer
11
 * el archivo LICENSE que se distribuye con el código fuente.
12
 * For more information, see <https://www.gpupo.com/>.
13
 */
14
15
namespace Gpupo\NetshoesSdk\Console\Command;
16
17
use Symfony\Component\Console\Input\InputArgument;
18
use Symfony\Component\Console\Input\InputInterface;
19
use Symfony\Component\Console\Output\OutputInterface;
20
21
/**
22
 * @codeCoverageIgnore
23
 */
24
final class TemplatesCommand extends AbstractCommand
25
{
26
    public function main($app)
27
    {
28
        foreach ([
29
            'brands',
30
            'flavors',
31
            'colors',
32
            'sizes',
33
        ] as $templateKey) {
34
            $this->getApp()->appendCommand('templates:'.$templateKey, 'List of '.$templateKey)
35 View Code Duplication
                ->setCode(function (InputInterface $input, OutputInterface $output) use ($app, $templateKey) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
36
                    $list = $app->processInputParameters([], $input, $output);
37
                    $responseList = $app->factorySdk($list)->factoryManager('templates')->fetchByRoute($templateKey);
38
                    $app->displayTableResults($output, $responseList);
39
                });
40
        }
41
42
        $this->getApp()->appendCommand('templates:departments', 'List of departments')
43
            ->addArgument('buId', InputArgument::REQUIRED, 'Business unit id - NS = Netshoes e ZT = Zattini')
44 View Code Duplication
            ->setCode(function (InputInterface $input, OutputInterface $output) use ($app) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
45
                $list = $app->processInputParameters([], $input, $output);
46
                $responseList = $app->factorySdk($list)->factoryManager('templates')
47
                    ->fetchByRoute('departments', 0, 50, [
48
                        'buId' => $input->getArgument('buId'),
49
                    ]);
50
                $app->displayTableResults($output, $responseList);
51
            });
52
53
        $this->getApp()->appendCommand('templates:productTypes', 'List of productTypes')
54
            ->addArgument('departmentCode', InputArgument::REQUIRED, 'Id do departamento')
55 View Code Duplication
            ->setCode(function (InputInterface $input, OutputInterface $output) use ($app) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
56
                $list = $app->processInputParameters([], $input, $output);
57
                $responseList = $app->factorySdk($list)->factoryManager('templates')
58
                    ->fetchByRoute('productTypes', 0, 50, [
59
                        'departmentCode' => $input->getArgument('departmentCode'),
60
                    ]);
61
                $app->displayTableResults($output, $responseList);
62
            });
63
64
        $this->getApp()->appendCommand('templates:attributes', 'List of attributes')
65
            ->addArgument('departmentCode', InputArgument::REQUIRED, 'Id do departamento')
66
            ->addArgument('productTypeCode', InputArgument::REQUIRED, 'Id do Product Type')
67 View Code Duplication
            ->setCode(function (InputInterface $input, OutputInterface $output) use ($app) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
68
                $list = $app->processInputParameters([], $input, $output);
69
                $responseList = $app->factorySdk($list)->factoryManager('templates')
70
                    ->fetchByRoute('attributes', 0, 50, [
71
                        'departmentCode'  => $input->getArgument('departmentCode'),
72
                        'productTypeCode' => $input->getArgument('productTypeCode'),
73
                    ]);
74
                $app->displayTableResults($output, $responseList);
75
            });
76
77
        $this->getApp()->appendCommand('templates:tree', 'Tree of templates')
78
            ->addArgument('buId', InputArgument::REQUIRED, 'Business unit id - NS = Netshoes e ZT = Zattini')
79
            ->setCode(function (InputInterface $input, OutputInterface $output) use ($app) {
80
                $list = $app->processInputParameters([], $input, $output);
81
                $buId = $input->getArgument('buId');
82
                $manager = $app->factorySdk($list)->factoryManager('templates');
83
84
                $departaments = $manager->fetchByRoute('departments', 0, 50, [
85
                    'buId' => $buId,
86
                ]);
87
88
                foreach ($departaments as $departament) {
89
                    $output->writeln('<info>'.$departament->getId().'</info> '.$departament->getName());
90
91
                    $types = $manager->fetchByRoute('productTypes', 0, 50, [
92
                            'departmentCode' => $departament->getId(),
93
                    ]);
94
95
                    foreach ($types as $type) {
96
                        $output->writeln("\t - ".'<fg=yellow>'.$type->getId().'</> '.$type->getName());
97
                    }
98
99
                    $output->writeln('<fg=yellow>------</>');
100
                }
101
            });
102
103
        return $app;
104
    }
105
}
106