Completed
Push — master ( f3d682...6367b5 )
by Gilmar
21:40
created

Manager::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 0
cts 0
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
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\NetshoesSdk\Entity\AbstractManager;
18
use Gpupo\NetshoesSdk\Entity\Order\Shippings\Shippings;
19
20
class Manager extends AbstractManager
21
{
22
    protected $entity = 'Order';
23
24
    /**
25
     * @codeCoverageIgnore
26
     * @SuppressWarnings(PHPMD.cpd)
27
     */
28
    protected function setUp()
29
    {
30
        $this->maps = include 'map.php';
31
    }
32
33 1
    protected function factoryDecorator(Order $order, $decoratorName)
34
    {
35 1
        $className = __NAMESPACE__.'\\Decorator\\'.$decoratorName;
36 1
        $instance = new $className();
37 1
        $instance->setOrder($order);
38
39 1
        return $instance;
40
    }
41
42
    public function updateStatus(Order $order)
43
    {
44
        $status = $order->getOrderStatus();
45
46
        if (in_array($status, ['approved', 'canceled', 'delivered', 'invoiced', 'shipped'], true)) {
47
            $decorator = $this->factoryDecorator($order, 'Status\\'.ucfirst($status));
48
49
            $json = $decorator->toJson();
50
            $mapKey = 'to'.ucfirst($status);
51
52
            $shipping = $order->getShipping();
53
            $code = $shipping->getShippingCode();
54
55
            $shipping->toJson();
56
57
            $map = $this->factoryMap($mapKey, [
58
                'orderNumber'  => $order->getOrderNumber(),
59
                'shippingCode' => $code,
60
            ]);
61
62
            $response = $this->execute($map, $json);
0 ignored issues
show
Unused Code introduced by
$response is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
63
64
            return true;
65
        }
66
67
        throw new \InvalidArgumentException('Order Status não suportado', 1);
68
    }
69
70
    /**
71
     * @return Gpupo\Common\Entity\CollectionAbstract|null
72
     */
73
    public function fetchShippings($orderNumber)
74
    {
75
        $response = $this->perform($this->factoryMap('fetchShippings', [
76
            'orderNumber' => $orderNumber,
77
        ]));
78
79
        $data = $this->processResponse($response);
80
81
        if (empty($data)) {
82
            return;
83
        }
84
85
        return new Shippings($data->toArray());
86
    }
87
}
88