Completed
Push — master ( 3347ae...8ec7fe )
by Romain
9s
created

ReceiptElement::__construct()   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 2
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 int $quantity
37
     * @return ReceiptElement
38
     */
39
    public function setQuantity(int $quantity): ReceiptElement
40
    {
41
        $this->quantity = $quantity;
42
43
        return $this;
44
    }
45
46
    /**
47
     * @param string $currency
48
     * @return ReceiptElement
49
     */
50
    public function setCurrency(string $currency): ReceiptElement
51
    {
52
        $this->isValidCurrency($currency);
53
        $this->currency = $currency;
54
55
        return $this;
56
    }
57
58
    /**
59
     * @return array
60
     */
61
    public function jsonSerialize(): array
62
    {
63
        $json = parent::jsonSerialize();
64
        $json += [
65
            'subtitle' => $this->subtitle,
66
            'quantity' => $this->quantity,
67
            'price' => $this->price,
68
            'currency' => $this->currency,
69
            'image_url' => $this->imageUrl,
70
        ];
71
72
        return array_filter($json);
73
    }
74
}
75