Completed
Push — master ( c0037b...566a0a )
by Gilmar
26:57
created

Order   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 91
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 9
Bugs 1 Features 0
Metric Value
wmc 10
c 9
b 1
f 0
lcom 1
cbo 1
dl 0
loc 91
rs 10
ccs 23
cts 23
cp 1

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getSchema() 0 23 1
A setUp() 0 4 1
A getInvoice() 0 4 1
A getItems() 0 4 1
A toLog() 0 15 1
A getShipping() 0 10 2
A check() 0 6 1
A getOrderDate() 0 10 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\Common\Entity\CollectionInterface;
18
use Gpupo\CommonSdk\Entity\EntityAbstract;
19
use Gpupo\CommonSdk\Entity\EntityInterface;
20
21
/**
22
 * @method string getAgreedDate()    Acesso a agreedDate
23
 * @method setAgreedDate(string $agreedDate)    Define agreedDate
24
 * @method string getBusinessUnit()    Acesso a businessUnit
25
 * @method setBusinessUnit(string $businessUnit)    Define businessUnit
26
 * @method bool getDevolutionRequested()    Acesso a devolutionRequested
27
 * @method setDevolutionRequested(boolean $devolutionRequested)    Define devolutionRequested
28
 * @method bool getExchangeRequested()    Acesso a exchangeRequested
29
 * @method setExchangeRequested(boolean $exchangeRequested)    Define exchangeRequested
30
 * @method setOrderDate(string $orderDate)    Define orderDate
31
 * @method string getOrderNumber()    Acesso a orderNumber
32
 * @method setOrderNumber(string $orderNumber)    Define orderNumber
33
 * @method string getOrderStatus()    Acesso a orderStatus
34
 * @method setOrderStatus(string $orderStatus)    Define orderStatus
35
 * @method string getOrderType()    Acesso a orderType
36
 * @method setOrderType(string $orderType)    Define orderType
37
 * @method string getOriginNumber()    Acesso a originNumber
38
 * @method setOriginNumber(string $originNumber)    Define originNumber
39
 * @method string getOriginSite()    Acesso a originSite
40
 * @method setOriginSite(string $originSite)    Define originSite
41
 * @method string getPaymentDate()    Acesso a paymentDate
42
 * @method setPaymentDate(string $paymentDate)    Define paymentDate
43
 * @method Gpupo\NetshoesSdk\Entity\Order\Shippings\Shippings getShippings()    Acesso a shippings
44
 * @method setShippings(Gpupo\NetshoesSdk\Entity\Order\Shippings\Shippings $shippings)    Define shippings
45
 * @method float getTotalCommission()    Acesso a totalCommission
46
 * @method setTotalCommission(float $totalCommission)    Define totalCommission
47
 * @method float getTotalDiscount()    Acesso a totalDiscount
48
 * @method setTotalDiscount(float $totalDiscount)    Define totalDiscount
49
 * @method float getTotalFreight()    Acesso a totalFreight
50
 * @method setTotalFreight(float $totalFreight)    Define totalFreight
51
 * @method float getTotalGross()    Acesso a totalGross
52
 * @method setTotalGross(float $totalGross)    Define totalGross
53
 * @method float getTotalNet()    Acesso a totalNet
54
 * @method setTotalNet(float $totalNet)    Define totalNet
55
 * @method float getTotalQuantity()    Acesso a totalQuantity
56
 * @method setTotalQuantity(float $totalQuantity)    Define totalQuantity
57
 */
58
class Order extends EntityAbstract implements EntityInterface, CollectionInterface
59
{
60
    protected $primaryKey = 'orderNumber';
61
62
    /**
63
     * @codeCoverageIgnore
64
     */
65
    public function getSchema()
66
    {
67
        return [
68
            'agreedDate'          => 'string',
69
            'businessUnit'        => 'string',
70
            'devolutionRequested' => 'boolean',
71
            'exchangeRequested'   => 'boolean',
72
            'orderDate'           => 'string',
73
            'orderNumber'         => 'string',
74
            'orderStatus'         => 'string',
75
            'orderType'           => 'string',
76
            'originNumber'        => 'string',
77
            'originSite'          => 'string',
78
            'paymentDate'         => 'string',
79
            'shippings'           => 'object',
80
            'totalCommission'     => 'number',
81
            'totalDiscount'       => 'number',
82
            'totalFreight'        => 'number',
83
            'totalGross'          => 'number',
84
            'totalNet'            => 'number',
85
            'totalQuantity'       => 'number',
86
        ];
87
    }
88
89 4
    protected function setUp()
90
    {
91 4
        $this->setOptionalSchema(['devolutionRequested', 'exchangeRequested']);
92 4
    }
93
94 1
    public function toLog()
95
    {
96 1
        return $this->partitionByArrayKey([
97 1
            'orderDate',
98
            'orderNumber',
99
            'orderStatus',
100
            'orderType',
101
            'originNumber',
102
            'originSite',
103
            'paymentDate',
104
            'totalFreight',
105
            'totalNet',
106
            'totalQuantity',
107
        ]);
108
    }
109
110 8
    public function getShipping()
111
    {
112 8
        $shipping = $this->getShippings()->first();
113
114 8
        if (empty($shipping)) {
115 1
            throw new \Exception('Shipping Missed!');
116
        }
117
118 7
        return $shipping;
119
    }
120
121 3
    public function getInvoice()
122
    {
123 3
        return $this->getShipping()->getInvoice();
124
    }
125
126 4
    public function getItems()
127
    {
128 4
        return $this->getShipping()->getItems();
129
    }
130
131 1
    public function check()
132
    {
133 1
        $this->setRequiredSchema(['businessUnit', 'orderDate', 'orderNumber']);
134
135 1
        return $this->isValid();
136
    }
137
138 5
    public function getOrderDate()
139
    {
140 5
        $od = $this->get('orderDate');
141
142 5
        if (intval($od) === $od) {
143 3
            return date('Y-m-d', $od / 1000);
144
        }
145
146 3
        return $od;
147
    }
148
}
149