TemplatesCommand   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 82
Duplicated Lines 36.59 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 4
dl 30
loc 82
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B main() 30 79 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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