Completed
Push — master ( b44bca...6404c7 )
by Gilmar
22:18
created

Manager::updateStatus()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 24
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 2

Importance

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