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

AutomaticWriteOff   A

Coupling/Cohesion

Components 1
Dependencies 0

Complexity

Total Complexity 8

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Test Coverage

Coverage 47.83%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 0
dl 0
loc 81
ccs 11
cts 23
cp 0.4783
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getSetting() 0 4 1
A withSetting() 0 7 1
A getAmount() 0 4 1
A withAmount() 0 7 1
A toArray() 0 10 3
A createFromArray() 0 8 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