BillogramCallback::toArray()   A
last analyzed

Complexity

Conditions 4
Paths 8

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 0
cts 9
cp 0
rs 9.8333
c 0
b 0
f 0
cc 4
nc 8
nop 0
crap 20
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Billogram\Model\Invoice;
6
7
use Billogram\Model\CreatableFromArray;
8
9
/**
10
 * @author Ibrahim Hizeoui <[email protected]>
11
 */
12
class BillogramCallback implements CreatableFromArray
13
{
14
    /**
15
     * @var string
16
     */
17
    private $url;
18
19
    /**
20
     * @var string
21
     */
22
    private $custom;
23
24
    /**
25
     * @var string
26
     */
27
    private $signKey;
28
29
    /**
30
     * @return string
31
     */
32
    public function getUrl(): string
33
    {
34
        return $this->url;
35
    }
36
37
    /**
38
     * @param string $url
39
     *
40
     * @return BillogramCallback
41
     */
42
    public function withUrl(string $url)
43
    {
44
        $new = clone $this;
45
        $new->url = $url;
46
47
        return $new;
48
    }
49
50
    /**
51
     * @return string
52
     */
53
    public function getCustom(): string
54
    {
55
        return $this->custom;
56
    }
57
58
    /**
59
     * @param string $custom
60
     *
61
     * @return BillogramCallback
62
     */
63
    public function withCustom(string $custom)
64
    {
65
        $new = clone $this;
66
        $new->custom = $custom;
67
68
        return $new;
69
    }
70
71
    /**
72
     * @return string
73
     */
74
    public function getSignKey(): string
75
    {
76
        return $this->signKey;
77
    }
78
79
    /**
80
     * @param string $signKey
81
     *
82
     * @return BillogramCallback
83
     */
84
    public function withSignKey(string $signKey)
85
    {
86
        $new = clone $this;
87
        $new->signKey = $signKey;
88
89
        return $new;
90
    }
91
92
    public function toArray()
93
    {
94
        $data = [];
95
        if (null !== $this->url) {
96
            $data['url'] = $this->url;
97
        }
98
        if (null !== $this->custom) {
99
            $data['custom'] = $this->custom;
100
        }
101
        if (null !== $this->signKey) {
102
            $data['sign_key'] = $this->signKey;
103
        }
104
    }
105
106
    /**
107
     * Create an API response object from the HTTP response from the API server.
108
     *
109
     * @param array $data
110
     *
111
     * @return self
112
     */
113 3
    public static function createFromArray(array $data)
114
    {
115 3
        $billogramCallback = new self();
116 3
        $billogramCallback->url = $data['url'] ?? null;
117 3
        $billogramCallback->custom = $data['custom'] ?? null;
118 3
        $billogramCallback->signKey = $data['sign_key'] ?? null;
119
120 3
        return $billogramCallback;
121
    }
122
}
123