Completed
Push — master ( b6e75f...2f94b1 )
by Baldur
02:03
created

OrderTransaction::toArray()   B

Complexity

Conditions 4
Paths 8

Size

Total Lines 22
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 22
ccs 12
cts 12
cp 1
rs 8.9197
c 0
b 0
f 0
cc 4
eloc 12
nc 8
nop 0
crap 4
1
<?php
2
3
namespace LAShowroom\TaxJarBundle\Model\Transaction;
4
5
use LAShowroom\TaxJarBundle\Model\BaseRequest;
6
use Webmozart\Assert\Assert;
7
8
class OrderTransaction extends BaseRequest
9
{
10
    /**
11
     * @var string
12
     */
13
    private $transactionId;
14
15
    /**
16
     * @var \DateTime
17
     */
18
    private $transactionDate;
19
20
    /**
21
     * @var float
22
     */
23
    private $salesTax;
24
25
    /**
26
     * @var LineItem[]
27
     */
28
    private $lineItems = [];
29
30
    /**
31
     * @return string
32
     */
33 2
    public function getTransactionId()
34
    {
35 2
        return $this->transactionId;
36
    }
37
38
    /**
39
     * @param string $transactionId
40
     */
41 4
    public function setTransactionId($transactionId)
42
    {
43 4
        $this->transactionId = $transactionId;
44 4
    }
45
46
    /**
47
     * @return \DateTime
48
     */
49 2
    public function getTransactionDate()
50
    {
51 2
        return $this->transactionDate;
52
    }
53
54
    /**
55
     * @param \DateTime $transactionDate
56
     */
57 4
    public function setTransactionDate(\DateTime $transactionDate)
58
    {
59 4
        $this->transactionDate = $transactionDate;
60 4
    }
61
62
    /**
63
     * @return float
64
     */
65 2
    public function getSalesTax()
66
    {
67 2
        return $this->salesTax;
68
    }
69
70
    /**
71
     * @param float $salesTax
72
     */
73 4
    public function setSalesTax($salesTax)
74
    {
75 4
        Assert::float($salesTax);
76
77 4
        $this->salesTax = $salesTax;
78 4
    }
79
80
    /**
81
     * @return LineItem[]
82
     */
83 4
    public function getLineItems()
84
    {
85 4
        return $this->lineItems;
86
    }
87
88
    /**
89
     * @param LineItem[] $lineItems
90
     */
91 2
    public function setLineItems(array $lineItems)
92
    {
93 2
        Assert::allIsInstanceOf($lineItems, LineItem::class);
94
95 2
        $this->lineItems = $lineItems;
96 2
    }
97
98 4
    public function addLineItem(LineItem $lineItem)
99
    {
100 4
        $this->lineItems[] = $lineItem;
101 4
    }
102
103 4
    public function toArray()
104
    {
105 4
        $result = [];
106
107 4
        if (!empty($this->transactionId)) {
108 4
            $result['transaction_id'] = $this->transactionId;
109
        }
110
111 4
        if (!empty($this->transactionDate)) {
112 4
            $result['transaction_date'] = $this->transactionDate->format(\DateTime::ISO8601);
113
        }
114
115 4
        if (!empty($this->salesTax)) {
116 4
            $result['sales_tax'] = $this->salesTax;
117
        }
118
119 4
        $result['line_items'] = array_map(function(LineItem $elem) {
120 2
            return $elem->toArray();
121 4
        }, $this->lineItems);
122
123 4
        return array_merge(parent::toArray(), $result);
124
    }
125
}
126