Completed
Push — master ( 9da17b...7475e6 )
by Gilmar
22:57
created

TemplatesCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 93
Duplicated Lines 26.88 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 0
cbo 3
dl 25
loc 93
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B append() 25 90 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 full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 * For more information, see <http://www.g1mr.com/>.
9
 */
10
namespace Gpupo\NetshoesSdk\Console\Command;
11
12
use Gpupo\NetshoesSdk\Console\Application;
13
use Symfony\Component\Console\Input\InputArgument;
14
use Symfony\Component\Console\Input\InputInterface;
15
use Symfony\Component\Console\Output\OutputInterface;
16
17
class TemplatesCommand
18
{
19
    public static function append(Application $app)
20
    {
21
        foreach ([
22
            'brands',
23
            'flavors',
24
            'colors',
25
            'sizes',
26
        ] as $templateKey) {
27
            $app->appendCommand('templates:' . $templateKey, 'List of ' . $templateKey)
28
                ->setCode(function (InputInterface $input, OutputInterface $output) use ($app, $templateKey) {
29
                    $list = $app->processInputParameters([], $input, $output);
30
                    $responseList = $app->factorySdk($list)->factoryManager('templates')->fetchByRoute($templateKey);
31
                    $app->displayTableResults($output, $responseList);
32
            });
33
        }
34
35
        $app->appendCommand('templates:departments', 'List of departments')
36
            ->addArgument('buId', InputArgument::REQUIRED, 'Business unit id - NS = Netshoes e ZT = Zattini')
37 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...
38
                $list = $app->processInputParameters([], $input, $output);
39
                $responseList = $app->factorySdk($list)->factoryManager('templates')
40
                    ->fetchByRoute('departments', 0, 50, [
41
                        'buId' => $input->getArgument('buId'),
42
                    ]);
43
                $app->displayTableResults($output, $responseList);
44
        });
45
46
        $app->appendCommand('templates:productTypes', 'List of productTypes')
47
            ->addArgument('departmentCode', InputArgument::REQUIRED, 'Id do departamento')
48 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...
49
                $list = $app->processInputParameters([], $input, $output);
50
                $responseList = $app->factorySdk($list)->factoryManager('templates')
51
                    ->fetchByRoute('productTypes', 0, 50, [
52
                        'departmentCode' => $input->getArgument('departmentCode'),
53
                    ]);
54
                $app->displayTableResults($output, $responseList);
55
        });
56
57
        $app->appendCommand('templates:attributes', 'List of attributes')
58
            ->addArgument('departmentCode', InputArgument::REQUIRED, 'Id do departamento')
59
            ->addArgument('productTypeCode', InputArgument::REQUIRED, 'Id do Product Type')
60 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...
61
                $list = $app->processInputParameters([], $input, $output);
62
                $responseList = $app->factorySdk($list)->factoryManager('templates')
63
                    ->fetchByRoute('attributes', 0, 50, [
64
                        'departmentCode'  => $input->getArgument('departmentCode'),
65
                        'productTypeCode' => $input->getArgument('productTypeCode'),
66
                    ]);
67
                $app->displayTableResults($output, $responseList);
68
        });
69
70
        $app->appendCommand('templates:tree', 'Tree of templates')
71
            ->addArgument('buId', InputArgument::REQUIRED, 'Business unit id - NS = Netshoes e ZT = Zattini')
72
            ->setCode(function (InputInterface $input, OutputInterface $output) use ($app) {
73
                $list = $app->processInputParameters([], $input, $output);
74
                $buId = $input->getArgument('buId');
75
                $manager = $app->factorySdk($list)->factoryManager('templates');
76
77
                $departaments = $manager->fetchByRoute('departments', 0, 50, [
78
                    'buId' => $buId,
79
                ]);
80
81
                foreach ($departaments as $departament) {
82
                    $output->writeln('<info>' . $departament->getId() . '</info> ' . $departament->getName());
83
84
                    $types = $manager->fetchByRoute('productTypes', 0, 50, [
85
                            'departmentCode' => $departament->getId(),
86
                    ]);
87
88
                    foreach ($types as $type) {
89
                        $output->writeln("\t - " . '<fg=yellow>' . $type->getId() . '</> ' . $type->getName());
90
91
                        $attributes = $manager->fetchByRoute('attributes', 0, 50, [
0 ignored issues
show
Unused Code introduced by
$attributes is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
92
                                'departmentCode'  => $departament->getId(),
93
                                'productTypeCode' => $type->getId(),
94
                        ]);
95
96
                        /*
97
                        foreach($attributes as $attribute) {
98
                            $output->writeln("\t\t * " . '<fg=blue>'.$attribute->getId().'</> ' . $attribute->getName());
99
                        }
100
                        */
101
                    }
102
103
                    $output->writeln('<fg=yellow>------</>');
104
                }
105
        });
106
107
        return $app;
108
    }
109
}
110