Completed
Push — master ( ebc878...38207c )
by Gilmar
41:02 queued 16:13
created

SkuCommand   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 53
Duplicated Lines 50.94 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 10
Bugs 1 Features 0
Metric Value
wmc 3
c 10
b 1
f 0
lcom 0
cbo 4
dl 27
loc 53
ccs 0
cts 37
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A append() 27 50 3

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
11
namespace Gpupo\NetshoesSdk\Console\Command;
12
13
use Gpupo\NetshoesSdk\Console\Application;
14
use Symfony\Component\Console\Input\InputArgument;
15
use Symfony\Component\Console\Input\InputInterface;
16
use Symfony\Component\Console\Output\OutputInterface;
17
18
class SkuCommand extends AbstractCommand
19
{
20
    public static function append(Application $app)
21
    {
22
        $app->appendCommand('product:sku:view', 'Mostra os SKUs de um Produto')
23
            ->addArgument('productId', InputArgument::REQUIRED, 'Product ID')
24
            ->setCode(function (InputInterface $input, OutputInterface $output) use ($app) {
25
                $list = $app->processInputParameters([], $input, $output);
26
27
                $p = $app->factorySdk($list)->factoryManager('sku')->findById($input->getArgument('productId'));
28
29
                $app->displayTableResults($output, $p);
30
            });
31
32
        $app->appendCommand('product:sku:detail', 'Mostra preço, estoque e situação de um SKUs')
33
            ->addArgument('SkuId', InputArgument::REQUIRED, 'Sku ID')
34 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...
35
                $list = $app->processInputParameters([], $input, $output);
36
37
                $id = $input->getArgument('productId');
0 ignored issues
show
Unused Code introduced by
$id 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...
38
                $m = $app->factorySdk($list)->factoryManager('sku');
0 ignored issues
show
Unused Code introduced by
$m 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...
39
40
            });
41
42
        $insertOptions = [
43
            ['key' => 'file'],
44
        ];
45
46
        $app->appendCommand('product:sku:update', 'Atualiza um SKU')
47
            ->setDefinition($app->factoryDefinition($insertOptions))
48 View Code Duplication
            ->setCode(function (InputInterface $input, OutputInterface $output) use ($app, $insertOptions) {
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($insertOptions, $input, $output);
50
51
                $data = json_decode(file_get_contents($list['file']), true);
52
                $sdk = $app->factorySdk($list);
53
                $sku = $sdk->createSku($data);
54
55
                try {
56
                    $operation = $sdk->factoryManager('sku')->update($sku);
57
58
                    if (200 === $operation->getHttpStatusCode()) {
59
                        $output->writeln('<info>Successo!</info>');
60
                    }
61
                } catch (\Exception $e) {
62
                    $output->writeln('<error>Erro na criação</error>');
63
                    $output->writeln('Message: <comment>'.$e->getMessage().'</comment>');
64
                    $output->writeln('Error Code: <comment>'.$e->getCode().'</comment>');
65
                }
66
            });
67
68
        return $app;
69
    }
70
}
71