Completed
Push — master ( f2b799...761b51 )
by Tobias
04:02
created

AutomaticWriteOff::createFromArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Billogram\Model\Setting;
6
7
use Billogram\Model\CreatableFromArray;
8
9
/**
10
 * @author Ibrahim Hizeoui <[email protected]>
11
 */
12
class AutomaticWriteOff implements CreatableFromArray
13
{
14
    /**
15
     * @var string
16
     */
17
    private $setting;
18
19
    /**
20
     * @var int
21
     */
22
    private $amount;
23
24
    /**
25
     * @return string
26
     */
27
    public function getSetting()
28
    {
29
        return $this->setting;
30
    }
31
32
    /**
33
     * @param string $setting
34
     *
35
     * @return AutomaticWriteOff
36
     */
37
    public function withSetting(string $setting)
38
    {
39
        $new = clone $this;
40
        $new->setting = $setting;
41
42
        return $new;
43
    }
44
45
    /**
46
     * @return int
47
     */
48
    public function getAmount()
49
    {
50
        return $this->amount;
51
    }
52
53
    /**
54
     * @param int $amount
55
     *
56
     * @return AutomaticWriteOff
57
     */
58
    public function withAmount(int $amount)
59
    {
60
        $new = clone $this;
61
        $new->amount = $amount;
62
63
        return $new;
64
    }
65
66 1
    public function toArray()
67
    {
68 1
        $data = [];
69 1
        if ($this->setting !== null && $this->amount !== null) {
70 1
            $data['settings'] = $this->setting;
71 1
            $data['amount'] = $this->amount;
72
        }
73
74 1
        return $data;
75
    }
76
77
    /**
78
     * Create an API response object from the HTTP response from the API server.
79
     *
80
     * @param array $data
81
     *
82
     * @return self
83
     */
84 2
    public static function createFromArray(array $data)
85
    {
86 2
        $automaticWriteoff = new self();
87 2
        $automaticWriteoff->setting = $data['settings'] ?? null;
88 2
        $automaticWriteoff->amount = $data['amount'] ?? null;
89
90 2
        return $automaticWriteoff;
91
    }
92
}
93