Completed
Branch develop (c4337b)
by Romain
01:55
created

ReceiptElement::setSubtitle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
namespace Kerox\Messenger\Model\Message\Attachment\Template\Element;
3
4
class ReceiptElement extends AbstractElement
5
{
6
7
    /**
8
     * @var null|int
9
     */
10
    protected $quantity;
11
12
    /**
13
     * @var null|float
14
     */
15
    protected $price;
16
17
    /**
18
     * @var null|string
19
     */
20
    protected $currency;
21
22
    /**
23
     * Element constructor.
24
     *
25
     * @param string $title
26
     * @param float $price
27
     */
28
    public function __construct(string $title, float $price)
29
    {
30
        parent::__construct($title);
31
32
        $this->price = $price;
33
    }
34
35
    /**
36
     * @param string $subtitle
37
     * @return \Kerox\Messenger\Model\Message\Attachment\Template\Element\ReceiptElement
38
     */
39
    public function setSubtitle(string $subtitle): ReceiptElement
40
    {
41
        parent::setSubtitle($subtitle);
42
43
        return $this;
44
    }
45
46
    /**
47
     * @param string $imageUrl
48
     * @return \Kerox\Messenger\Model\Message\Attachment\Template\Element\ReceiptElement
49
     */
50
    public function setImageUrl(string $imageUrl): ReceiptElement
51
    {
52
        parent::setImageUrl($imageUrl);
53
54
        return $this;
55
    }
56
57
    /**
58
     * @param int $quantity
59
     * @return ReceiptElement
60
     */
61
    public function setQuantity(int $quantity): ReceiptElement
62
    {
63
        $this->quantity = $quantity;
64
65
        return $this;
66
    }
67
68
    /**
69
     * @param string $currency
70
     * @return ReceiptElement
71
     */
72
    public function setCurrency(string $currency): ReceiptElement
73
    {
74
        $this->isValidCurrency($currency);
75
        $this->currency = $currency;
76
77
        return $this;
78
    }
79
80
    /**
81
     * @return array
82
     */
83
    public function jsonSerialize(): array
84
    {
85
        $json = parent::jsonSerialize();
86
        $json += [
87
            'subtitle' => $this->subtitle,
88
            'quantity' => $this->quantity,
89
            'price' => $this->price,
90
            'currency' => $this->currency,
91
            'image_url' => $this->imageUrl,
92
        ];
93
94
        return array_filter($json);
95
    }
96
}
97