Passed
Pull Request — master (#83)
by Romain
03:05
created

Summary   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 99
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
dl 0
loc 99
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A setSubtotal() 0 5 1
A jsonSerialize() 0 3 1
A setShippingCost() 0 5 1
A toArray() 0 10 1
A create() 0 3 1
A setTotalTax() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Kerox\Messenger\Model\Message\Attachment\Template\Receipt;
6
7
class Summary implements \JsonSerializable
8
{
9
    /**
10
     * @var float
11
     */
12
    protected $subtotal;
13
14
    /**
15
     * @var float
16
     */
17
    protected $shippingCost;
18
19
    /**
20
     * @var float
21
     */
22
    protected $totalTax;
23
24
    /**
25
     * @var float
26
     */
27
    protected $totalCost;
28
29
    /**
30
     * Summary constructor.
31
     *
32 4
     * @param float $totalCost
33
     */
34 4
    public function __construct(float $totalCost)
35 4
    {
36
        $this->totalCost = $totalCost;
37
    }
38
39
    /**
40
     * @param float $totalCost
41
     *
42 4
     * @return \Kerox\Messenger\Model\Message\Attachment\Template\Receipt\Summary
43
     */
44 4
    public static function create(float $totalCost): self
45
    {
46 4
        return new self($totalCost);
47
    }
48
49
    /**
50
     * @param float $subtotal
51
     *
52
     * @return Summary
53
     */
54 4
    public function setSubtotal(float $subtotal): self
55
    {
56 4
        $this->subtotal = $subtotal;
57
58 4
        return $this;
59
    }
60
61
    /**
62
     * @param float $shippingCost
63
     *
64
     * @return Summary
65
     */
66 4
    public function setShippingCost(float $shippingCost): self
67
    {
68 4
        $this->shippingCost = $shippingCost;
69
70 4
        return $this;
71
    }
72
73
    /**
74
     * @param float $totalTax
75
     *
76 4
     * @return Summary
77
     */
78
    public function setTotalTax(float $totalTax): self
79 4
    {
80 4
        $this->totalTax = $totalTax;
81 4
82 4
        return $this;
83
    }
84
85 4
    /**
86
     * @return array
87
     */
88
    public function toArray(): array
89
    {
90
        $array = [
91
            'subtotal'      => $this->subtotal,
92
            'shipping_cost' => $this->shippingCost,
93
            'total_tax'     => $this->totalTax,
94
            'total_cost'    => $this->totalCost,
95
        ];
96
97
        return array_filter($array);
98
    }
99
100
    /**
101
     * @return array
102
     */
103
    public function jsonSerialize(): array
104
    {
105
        return $this->toArray();
106
    }
107
}
108