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

Order::toLog()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 12

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 15
rs 9.4285
ccs 3
cts 3
cp 1
cc 1
eloc 12
nc 1
nop 0
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\CommonSdk\Entity\EntityAbstract;
18
use Gpupo\CommonSdk\Entity\EntityInterface;
19
20
/**
21
 * @method string getAgreedDate()    Acesso a agreedDate
22
 * @method setAgreedDate(string $agreedDate)    Define agreedDate
23
 * @method string getBusinessUnit()    Acesso a businessUnit
24
 * @method setBusinessUnit(string $businessUnit)    Define businessUnit
25
 * @method bool getDevolutionRequested()    Acesso a devolutionRequested
26
 * @method setDevolutionRequested(boolean $devolutionRequested)    Define devolutionRequested
27
 * @method bool getExchangeRequested()    Acesso a exchangeRequested
28
 * @method setExchangeRequested(boolean $exchangeRequested)    Define exchangeRequested
29
 * @method string getOrderDate()    Acesso a orderDate
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
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 1
    public function toLog()
90
    {
91 1
        return $this->partitionByArrayKey([
92 1
            'orderDate',
93
            'orderNumber',
94
            'orderStatus',
95
            'orderType',
96
            'originNumber',
97
            'originSite',
98
            'paymentDate',
99
            'totalFreight',
100
            'totalNet',
101
            'totalQuantity',
102
        ]);
103
    }
104
105 14
    public function getShipping()
106
    {
107 14
        $shipping = $this->getShippings()->first();
108
109 14
        if (empty($shipping)) {
110 1
            throw new \Exception('Shipping Missed!');
111
        }
112
113 13
        return $shipping;
114
    }
115
116 5
    public function getInvoice()
117
    {
118 5
        return $this->getShipping()->getInvoice();
119
    }
120
121 1
    public function getItems()
122
    {
123 1
        return $this->getShipping()->getItems();
124
    }
125
126 15
    public function check()
127
    {
128 15
        $this->setRequiredSchema(['businessUnit', 'orderDate', 'orderNumber']);
129
130 15
        return $this->isValid();
131
    }
132
}
133