Completed
Push — master ( 3a0836...9121f1 )
by Gilmar
22:37
created

DetailCommand   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 0
cbo 3
dl 0
loc 40
ccs 0
cts 32
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B append() 0 37 3
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 <http://www.g1mr.com/>.
13
 */
14
15
namespace Gpupo\NetshoesSdk\Console\Command;
16
17
use Gpupo\NetshoesSdk\Console\Application;
18
use Symfony\Component\Console\Input\InputInterface;
19
use Symfony\Component\Console\Output\OutputInterface;
20
21
class DetailCommand extends AbstractCommand
22
{
23
    public static function append(Application $app)
24
    {
25
        $insertOptions = [
26
            ['key' => 'file'],
27
            [
28
                'key'       => 'type',
29
                'options'   => ['Price', 'PriceSchedule', 'Stock', 'Status'],
30
                'default'   => 'Price'
31
            ],
32
        ];
33
34
        $app->appendCommand('product:sku:detail:update', 'Atualiza detalhes de um SKU')
35
            ->setDefinition($app->factoryDefinition($insertOptions))
36
            ->setCode(function (InputInterface $input, OutputInterface $output) use ($app, $insertOptions) {
37
                $list = $app->processInputParameters($insertOptions, $input, $output);
38
39
                $data = json_decode(file_get_contents($list['file']), true);
40
                $sdk = $app->factorySdk($list);
41
                $sku = $sdk->createSku($data);
42
43
                try {
44
                    $type = ucfirst($list['type']);
45
                    $operation = $sdk->factoryManager('sku')->saveDetail($sku, $type);
46
47
                    if (200 === $operation->getHttpStatusCode()) {
48
                        $output->writeln('Atualizando <comment>'.$type.'</comment>');
49
                        $output->writeln('<info>Successo!</info>');
50
                    }
51
                } catch (\Exception $e) {
52
                    $output->writeln('<error>Erro na criação</error>');
53
                    $output->writeln('Message: <comment>'.$e->getMessage().'</comment>');
54
                    $output->writeln('Error Code: <comment>'.$e->getCode().'</comment>');
55
                }
56
            });
57
58
        return $app;
59
    }
60
}
61