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

Adjustment::toArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 0
cts 0
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Kerox\Messenger\Model\Message\Attachment\Template\Receipt;
6
7
class Adjustment implements \JsonSerializable
8
{
9
    /**
10
     * @var null|string
11
     */
12
    protected $name;
13
14
    /**
15
     * @var null|float
16
     */
17
    protected $amount;
18
19
    /**
20 4
     * Adjustment constructor.
21
     */
22 4
    public function __construct()
23
    {
24
    }
25
26
    /**
27
     * @return \Kerox\Messenger\Model\Message\Attachment\Template\Receipt\Adjustment
28
     */
29 4
    public static function create(): self
30
    {
31 4
        return new self();
32
    }
33 4
34
    /**
35
     * @param string $name
36
     *
37
     * @return Adjustment
38
     */
39
    public function setName(string $name): self
40
    {
41 4
        $this->name = $name;
42
43 4
        return $this;
44
    }
45 4
46
    /**
47
     * @param float $amount
48
     *
49
     * @return Adjustment
50
     */
51 4
    public function setAmount(float $amount): self
52
    {
53
        $this->amount = $amount;
54 4
55 4
        return $this;
56
    }
57
58 4
    /**
59
     * @return array
60
     */
61
    public function toArray(): array
62
    {
63
        $array = [
64
            'name'   => $this->name,
65
            'amount' => $this->amount,
66
        ];
67
68
        return array_filter($array);
69
    }
70
71
    /**
72
     * @return array
73
     */
74
    public function jsonSerialize(): array
75
    {
76
        return $this->toArray();
77
    }
78
}
79