Completed
Push — master ( c760c9...0378e2 )
by Baldur
02:05
created

BaseRequest::setAmount()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
3
namespace LAShowroom\TaxJarBundle\Model;
4
5
use Webmozart\Assert\Assert;
6
7
class BaseRequest
8
{
9
    /**
10
     * @var Address
11
     */
12
    protected $fromAddress;
13
14
    /**
15
     * @var Address
16
     */
17
    protected $toAddress;
18
19
    /**
20
     * @var float
21
     */
22
    protected $amount;
23
24
    /**
25
     * @var float
26
     */
27
    protected $shipping;
28
29
    /**
30
     * @return Address
31
     */
32 2
    public function getFromAddress()
33
    {
34 2
        return $this->fromAddress;
35
    }
36
37
    /**
38
     * @param Address $fromAddress
39
     */
40 16
    public function setFromAddress(Address $fromAddress)
41
    {
42 16
        $this->fromAddress = $fromAddress;
43 16
    }
44
45
    /**
46
     * @return Address
47
     */
48 2
    public function getToAddress()
49
    {
50 2
        return $this->toAddress;
51
    }
52
53
    /**
54
     * @param Address $toAddress
55
     */
56 16
    public function setToAddress(Address $toAddress)
57
    {
58 16
        $this->toAddress = $toAddress;
59 16
    }
60
61
    /**
62
     * @return float
63
     */
64 16
    public function getAmount()
65
    {
66 16
        return $this->amount;
67
    }
68
69
    /**
70
     * @param float $amount
71
     */
72 14
    public function setAmount($amount)
73
    {
74 14
        Assert::float($amount);
75
76 14
        $this->amount = $amount;
77 14
    }
78
79
    /**
80
     * @return float
81
     */
82 16
    public function getShipping()
83
    {
84 16
        return $this->shipping;
85
    }
86
87
    /**
88
     * @param float $shipping
89
     */
90 14
    public function setShipping($shipping)
91
    {
92 14
        Assert::float($shipping);
93
94 14
        $this->shipping = $shipping;
95 14
    }
96
97 16
    protected function toArray()
98
    {
99 16
        $result = [];
100
101 16
        if (!empty($this->fromAddress)) {
102 14
            $result = array_merge($result, $this->fromAddress->toArray('from_'));
103
        }
104
105 16
        if (!empty($this->toAddress)) {
106 14
            $result = array_merge($result, $this->toAddress->toArray('to_'));
107
        }
108
109 16
        $result = array_merge($result, [
110 16
            'amount' => $this->getAmount(),
111 16
            'shipping' => $this->getShipping(),
112
        ]);
113
114 16
        return $result;
115
    }
116
}
117