Completed
Push — master ( c7990b...4ae46d )
by Gilmar
24:18
created

Manager::export()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 1
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\Entity\Order;
16
17
use Gpupo\NetshoesSdk\Entity\AbstractManager;
18
19
class Manager extends AbstractManager
20
{
21
    protected $entity = 'Order';
22
23
    /**
24
     * @codeCoverageIgnore
25
     */
26
    protected function setUp()
27
    {
28
        $this->maps = include 'map.config.php';
29
    }
30
31 1
    protected function factoryDecorator(Order $order, $decoratorName)
32
    {
33 1
        $className = __NAMESPACE__.'\\Decorator\\'.$decoratorName;
34 1
        $instance = new $className();
35 1
        $instance->setOrder($order);
36
37 1
        return $instance;
38
    }
39
40 1
    public function export(Order $order)
41
    {
42 1
        $decorator = $this->factoryDecorator($order, 'CommonSchema');
43
44 1
        return $decorator->toArray();
45
    }
46
47 7
    public function updateStatus(Order $order)
48
    {
49 7
        $status = $order->getOrderStatus();
50
51 7
        $list = ['approved', 'canceled', 'delivered', 'invoiced', 'shipped'];
52
53 7
        if (in_array($status, $list, true)) {
54 6
            $decorator = $this->factoryDecorator($order, 'Status\\'.ucfirst($status));
55 6
            $json = $decorator->toJson();
56 6
            $mapKey = 'to'.ucfirst($status);
57 6
            $shipping = $order->getShipping();
58 6
            $code = $shipping->getShippingCode();
59 6
            $shipping->toJson();
60 5
            $map = $this->factoryMap($mapKey, [
61 5
                'orderNumber'  => $order->getOrderNumber(),
62 5
                'itemId'       => $order->getOrderNumber(),
63 5
                'shippingCode' => $code,
64
            ]);
65
66 5
            return $this->execute($map, $json);
67
        }
68
69 1
        throw new \InvalidArgumentException('Order Status não suportado', 1);
70
    }
71
}
72