Completed
Push — master ( 6367b5...e868c1 )
by Gilmar
25:44 queued 01:46
created

Manager::fetchShippings()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 14
ccs 0
cts 7
cp 0
rs 9.4285
cc 2
eloc 7
nc 2
nop 1
crap 6
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.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 7
    public function updateStatus(Order $order)
41
    {
42 7
        $status = $order->getOrderStatus();
43
44 7
        $list = ['approved', 'canceled', 'delivered', 'invoiced', 'shipped'];
45
46 7
        if (in_array($status, $list, true)) {
47 6
            $decorator = $this->factoryDecorator($order, 'Status\\'.ucfirst($status));
48 6
            $json = $decorator->toJson();
49 6
            $mapKey = 'to'.ucfirst($status);
50 6
            $shipping = $order->getShipping();
51 6
            $code = $shipping->getShippingCode();
52 6
            $shipping->toJson();
53 5
            $map = $this->factoryMap($mapKey, [
54 5
                'orderNumber'  => $order->getOrderNumber(),
55 5
                'shippingCode' => $code,
56
            ]);
57
58 5
            $this->execute($map, $json);
59
60 5
            return true;
61
        }
62
63 1
        throw new \InvalidArgumentException('Order Status não suportado', 1);
64
    }
65
}
66