Completed
Push — master ( 700e42...8caa47 )
by Gilmar
39:30 queued 14:31
created

PriceCommand::append()   B

Complexity

Conditions 3
Paths 1

Size

Total Lines 30
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 30
ccs 0
cts 25
cp 0
rs 8.8571
cc 3
eloc 19
nc 1
nop 1
crap 12
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 PriceCommand extends AbstractCommand
19
{
20
    public static function append(Application $app)
21
    {
22
        $insertOptions = [
23
            ['key' => 'file'],
24
        ];
25
26
        $app->appendCommand('product:sku:price:update', 'Atualiza o preço de um SKU')
27
            ->setDefinition($app->factoryDefinition($insertOptions))
28
            ->setCode(function (InputInterface $input, OutputInterface $output) use ($app, $insertOptions) {
29
                $list = $app->processInputParameters($insertOptions, $input, $output);
30
31
                $data = json_decode(file_get_contents($list['file']), true);
32
                $sdk = $app->factorySdk($list);
33
                $sku = $sdk->createSku($data);
34
35
                try {                    
36
                    $operation = $sdk->factoryManager('sku')->saveDetail($sku, 'Price');
37
38
                    if (200 === $operation->getHttpStatusCode()) {
39
                        $output->writeln('<info>Successo!</info>');
40
                    }
41
                } catch (\Exception $e) {
42
                    $output->writeln('<error>Erro na criação</error>');
43
                    $output->writeln('Message: <comment>'.$e->getMessage().'</comment>');
44
                    $output->writeln('Error Code: <comment>'.$e->getCode().'</comment>');
45
                }
46
            });
47
48
        return $app;
49
    }
50
}
51