Completed
Push — master ( 168b8f...f2b799 )
by Tobias
02:41
created

Bookkeeping   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 83
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 50%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 0
dl 0
loc 83
ccs 12
cts 24
cp 0.5
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getIncomeAccount() 0 4 1
A withIncomeAccount() 0 7 1
A getVatAccount() 0 4 1
A withVatAccount() 0 7 1
A toArray() 0 12 3
A createFromArray() 0 8 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Billogram\Model\Item;
6
7
use Billogram\Model\CreatableFromArray;
8
9
/**
10
 * @author Ibrahim Hizeoui <[email protected]>
11
 */
12
class Bookkeeping implements CreatableFromArray
13
{
14
    /**
15
     * @var string
16
     */
17
    private $incomeAccount;
18
19
    /**
20
     * @var string
21
     */
22
    private $vatAccount;
23
24
    /**
25
     * @return string
26
     */
27
    public function getIncomeAccount(): string
28
    {
29
        return $this->incomeAccount;
30
    }
31
32
    /**
33
     * @param string $incomeAccount
34
     *
35
     * @return Bookkeeping
36
     */
37
    public function withIncomeAccount(string $incomeAccount)
38
    {
39
        $new = clone $this;
40
        $new->incomeAccount = $incomeAccount;
41
42
        return $new;
43
    }
44
45
    /**
46
     * @return string
47
     */
48
    public function getVatAccount(): string
49
    {
50
        return $this->vatAccount;
51
    }
52
53
    /**
54
     * @param string $vatAccount
55
     *
56
     * @return Bookkeeping
57
     */
58
    public function withVatAccount(string $vatAccount)
59
    {
60
        $new = clone $this;
61
        $new->vatAccount = $vatAccount;
62
63
        return $new;
64
    }
65
66 2
    public function toArray()
67
    {
68 2
        $data = [];
69 2
        if ($this->incomeAccount !== null) {
70 2
            $data['income_account'] = $this->incomeAccount;
71
        }
72 2
        if ($this->vatAccount !== null) {
73 2
            $data['vat_account'] = $this->vatAccount;
74
        }
75
76 2
        return $data;
77
    }
78
79
    /**
80
     * Create an API response object from the HTTP response from the API server.
81
     *
82
     * @param array $data
83
     *
84
     * @return self
85
     */
86 7
    public static function createFromArray(array $data)
87
    {
88 7
        $bookkeeping = new self();
89 7
        $bookkeeping->incomeAccount = $data['income_account'] ?? null;
90 7
        $bookkeeping->vatAccount = $data['vat_account'] ?? null;
91
92 7
        return $bookkeeping;
93
    }
94
}
95