ReceiptElement   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 101
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 101
ccs 27
cts 27
cp 1
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A create() 0 4 1
A setSubtitle() 0 6 1
A setImageUrl() 0 6 1
A setQuantity() 0 6 1
A setCurrency() 0 8 1
A toArray() 0 13 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Kerox\Messenger\Model\Message\Attachment\Template\Element;
6
7
class ReceiptElement extends AbstractElement
8
{
9
    /**
10
     * @var int|null
11
     */
12
    protected $quantity;
13
14
    /**
15
     * @var float|null
16
     */
17
    protected $price;
18
19
    /**
20
     * @var string|null
21
     */
22
    protected $currency;
23
24
    /**
25
     * Element constructor.
26
     *
27
     * @throws \Kerox\Messenger\Exception\MessengerException
28
     */
29 6
    public function __construct(string $title, float $price)
30
    {
31 6
        parent::__construct($title);
32
33 6
        $this->price = $price;
34 6
    }
35
36
    /**
37
     * @throws \Kerox\Messenger\Exception\MessengerException
38
     *
39
     * @return \Kerox\Messenger\Model\Message\Attachment\Template\Element\ReceiptElement
40
     */
41 6
    public static function create(string $title, float $price): self
42
    {
43 6
        return new self($title, $price);
44
    }
45
46
    /**
47
     * @throws \Kerox\Messenger\Exception\MessengerException
48
     *
49
     * @return \Kerox\Messenger\Model\Message\Attachment\Template\Element\ReceiptElement
50
     */
51 6
    public function setSubtitle(string $subtitle): self
52
    {
53 6
        parent::setSubtitle($subtitle);
54
55 6
        return $this;
56
    }
57
58
    /**
59
     * @throws \Kerox\Messenger\Exception\MessengerException
60
     *
61
     * @return \Kerox\Messenger\Model\Message\Attachment\Template\Element\ReceiptElement
62
     */
63 6
    public function setImageUrl(string $imageUrl): self
64
    {
65 6
        parent::setImageUrl($imageUrl);
66
67 6
        return $this;
68
    }
69
70
    /**
71
     * @return ReceiptElement
72
     */
73 6
    public function setQuantity(int $quantity): self
74
    {
75 6
        $this->quantity = $quantity;
76
77 6
        return $this;
78
    }
79
80
    /**
81
     * @throws \Kerox\Messenger\Exception\MessengerException
82
     *
83
     * @return ReceiptElement
84
     */
85 6
    public function setCurrency(string $currency): self
86
    {
87 6
        $this->isValidCurrency($currency);
88
89 6
        $this->currency = $currency;
90
91 6
        return $this;
92
    }
93
94 5
    public function toArray(): array
95
    {
96 5
        $array = parent::toArray();
97
        $array += [
98 5
            'subtitle' => $this->subtitle,
99 5
            'quantity' => $this->quantity,
100 5
            'price' => $this->price,
101 5
            'currency' => $this->currency,
102 5
            'image_url' => $this->imageUrl,
103
        ];
104
105 5
        return array_filter($array);
106
    }
107
}
108