Completed
Push — master ( d15f5b...9b96d8 )
by Gilmar
26:33
created

Order::toLog()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 15
rs 9.4285
ccs 0
cts 3
cp 0
cc 1
eloc 12
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\Common\Entity\CollectionInterface;
18
use Gpupo\CommonSdk\Entity\EntityAbstract;
19
use Gpupo\CommonSdk\Entity\EntityInterface;
20
use Gpupo\CommonSdk\Traits\LoadTrait;
21
22
/**
23
 * @method string getAgreedDate()    Acesso a agreedDate
24
 * @method setAgreedDate(string $agreedDate)    Define agreedDate
25
 * @method string getBusinessUnit()    Acesso a businessUnit
26
 * @method setBusinessUnit(string $businessUnit)    Define businessUnit
27
 * @method bool getDevolutionRequested()    Acesso a devolutionRequested
28
 * @method setDevolutionRequested(boolean $devolutionRequested)    Define devolutionRequested
29
 * @method bool getExchangeRequested()    Acesso a exchangeRequested
30
 * @method setExchangeRequested(boolean $exchangeRequested)    Define exchangeRequested
31
 * @method setOrderDate(string $orderDate)    Define orderDate
32
 * @method string getOrderNumber()    Acesso a orderNumber
33
 * @method setOrderNumber(string $orderNumber)    Define orderNumber
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
final class Order extends EntityAbstract implements EntityInterface, CollectionInterface
59
{
60
    use LoadTrait;
61
62
    protected $primaryKey = 'orderNumber';
63
64
    /**
65
     * @codeCoverageIgnore
66
     */
67
    public function getSchema()
68
    {
69
        return $this->loadArrayFromFile(__DIR__.'/map/schema.map.php');
70
    }
71
72 4
    protected function setUp()
73
    {
74 4
        $this->setOptionalSchema(['devolutionRequested', 'exchangeRequested']);
75 4
    }
76
77
    public function toLog()
78
    {
79
        return $this->partitionByArrayKey([
80
            'orderDate',
81
            'orderNumber',
82
            'orderStatus',
83
            'orderType',
84
            'originNumber',
85
            'originSite',
86
            'paymentDate',
87
            'totalFreight',
88
            'totalNet',
89
            'totalQuantity',
90
        ]);
91
    }
92
93 10
    public function getShipping()
94
    {
95 10
        $shipping = $this->getShippings()->first();
96
97 10
        if (empty($shipping)) {
98 1
            throw new \Exception('Shipping Missed!');
99
        }
100
101 9
        return $shipping;
102
    }
103
104 5
    public function getOrderStatus()
105
    {
106 5
        $value = $this->get('orderStatus');
107
108 5
        return strtolower($value);
109
    }
110
111 3
    public function getInvoice()
112
    {
113 3
        return $this->getShipping()->getInvoice();
114
    }
115
116 4
    public function getItems()
117
    {
118 4
        return $this->getShipping()->getItems();
119
    }
120
121 1
    public function check()
122
    {
123 1
        $this->setRequiredSchema(['businessUnit', 'orderDate', 'orderNumber']);
124
125 1
        return $this->isValid();
126
    }
127
128 5
    public function getOrderDate()
129
    {
130 5
        $od = $this->get('orderDate');
131
132 5
        if (intval($od) === $od) {
133 3
            return date('Y-m-d', $od / 1000);
134
        }
135
136 3
        return $od;
137
    }
138
}
139