Completed
Push — master ( f1c789...f35966 )
by Gilmar
36:36 queued 11:26
created

Application::displayProduct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 12
rs 9.4285
cc 1
eloc 8
nc 1
nop 2
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;
16
17
use Gpupo\CommonSdk\Console\AbstractApplication;
18
use Gpupo\NetshoesSdk\Entity\Order\Order;
19
use Gpupo\NetshoesSdk\Entity\Product\Product;
20
use Gpupo\NetshoesSdk\Factory;
21
use Symfony\Component\Console\Input\InputInterface;
22
use Symfony\Component\Console\Output\OutputInterface;
23
24
/**
25
 * @codeCoverageIgnore
26
 */
27
class Application extends AbstractApplication
28
{
29
    public function doRun(InputInterface $input, OutputInterface $output)
30
    {
31
        $output->writeln('<bg=green;options=bold>gpupo/netshoes-sdk</>');
32
        $output->writeln('<options=bold>Atenção! Esta aplicação é apenas uma '
33
        .'ferramenta de apoio ao desenvolvedor e não deve ser usada no ambiente de produção!'
34
        .'</>');
35
36
        return parent::doRun($input, $output);
37
    }
38
39
    protected $commonParameters = [
40
        [
41
            'key' => 'client_id',
42
        ],
43
        [
44
            'key' => 'access_token',
45
        ],
46
        [
47
            'key'     => 'env',
48
            'options' => ['sandbox', 'marketplace'],
49
            'default' => 'sandbox',
50
            'name'    => 'Version',
51
        ],
52
        [
53
            'key'     => 'sslVersion',
54
            'options' => ['SecureTransport', 'TLS'],
55
            'default' => 'SecureTransport',
56
            'name'    => 'SSL Version',
57
        ],
58
        [
59
            'key'     => 'registerPath',
60
            'default' => false,
61
        ],
62
    ];
63
64
    public function factorySdk(array $options, $loggerChannel = 'bin', $verbose = false)
65
    {
66
        return  Factory::getInstance()->setup($options, $this->factoryLogger($loggerChannel, $verbose));
67
    }
68
69
    public function displayOrder(Order $order, OutputInterface $output)
70
    {
71
        $output->writeln('Order #<comment>'.$order->getId().'</comment>');
72
        $this->displayTableResults($output, [$order->toLog()]);
73
        $output->writeln('Shipping - Order #<comment>'.$order->getId().'</comment>');
74
        $this->displayTableResults($output, [$order->getShipping()->toLog()]);
75
        $output->writeln('Shipping Items - Order #<comment>'.$order->getId().'</comment>');
76
        $this->displayTableResults($output, $order->getShipping()->getItems()->toLog());
77
    }
78
79
    public function displayProduct(Product $p, OutputInterface $output)
80
    {
81
        $this->displayTableResults($output, [[
82
            'Id'           => $p->getProductId(),
83
            'Brand'        => $p->getBrand(),
84
            'Department'   => $p->getDepartment(),
85
            'Product Type' => $p->getProductType(),
86
        ]]);
87
88
        $output->writeln('<fg=yellow>Skus</>');
89
        $this->displayTableResults($output, $p->getSkus());
90
    }
91
92
    public function jsonLoadFromFile($filename)
93
    {
94
        if (!file_exists($filename)) {
95
            throw new \Exception('Filename '.$filename.' not exists!');
96
        }
97
98
        $string = file_get_contents($filename);
99
100
        return json_decode($string, true);
101
    }
102
103
    public function jsonSaveToFile(array $array, $filename, OutputInterface $output)
104
    {
105
        $json = json_encode($array, JSON_PRETTY_PRINT);
106
        file_put_contents($filename, $json);
107
108
        return $output->writeln('Arquivo <info>'.$filename.'</info> gerado.');
109
    }
110
}
111