Completed
Push — master ( 9621c0...4bb787 )
by Tobias
01:47
created

Setting::toArray()   F

Complexity

Conditions 11
Paths 1024

Size

Total Lines 36
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 23
CRAP Score 11

Importance

Changes 0
Metric Value
dl 0
loc 36
ccs 23
cts 23
cp 1
rs 3.1764
c 0
b 0
f 0
cc 11
eloc 23
nc 1024
nop 0
crap 11

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
declare(strict_types=1);
4
5
namespace Billogram\Model\Setting;
6
7
use Billogram\Model\CreatableFromArray;
8
use Billogram\Model\Invoice\Invoices;
9
10
/**
11
 * @author Ibrahim Hizeoui <[email protected]>
12
 */
13
class Setting implements CreatableFromArray
14
{
15
    /**
16
     * @var string
17
     */
18
    private $name;
19
20
    /**
21
     * @var string
22
     */
23
    private $orgNo;
24
25
    /**
26
     * @var Contact
27
     */
28
    private $contact;
29
30
    /**
31
     * @var BusinessAddress
32
     */
33
    private $businessAddress;
34
35
    /**
36
     * @var InvoiceAddress
37
     */
38
    private $invoiceAddress;
39
40
    /**
41
     * @var VisitingAddress
42
     */
43
    private $visitingAddress;
44
45
    /**
46
     * @var PaymentSetting
47
     */
48
    private $payment;
49
50
    /**
51
     * @var TaxSetting
52
     */
53
    private $tax;
54
55
    /**
56
     * @var BookkeepingSetting
57
     */
58
    private $bookkeeping;
59
60
    /**
61
     * @var InvoiceDefaults
62
     */
63
    private $invoices;
64
65
    /**
66
     * @return string
67
     */
68
    public function getName()
69
    {
70
        return $this->name;
71
    }
72
73
    /**
74
     * @param string $name
75
     *
76
     * @return Setting
77
     */
78 1
    public function withName(string $name)
79
    {
80 1
        $new = clone $this;
81 1
        $new->name = $name;
82
83 1
        return $new;
84
    }
85
86
    /**
87
     * @return string
88
     */
89
    public function getOrgNo()
90
    {
91
        return $this->orgNo;
92
    }
93
94
    /**
95
     * @param string $orgNo
96
     *
97
     * @return Setting
98
     */
99 1
    public function withOrgNo(string $orgNo)
100
    {
101 1
        $new = clone $this;
102 1
        $new->orgNo = $orgNo;
103
104 1
        return $new;
105
    }
106
107
    /**
108
     * @return Contact
109
     */
110
    public function getContact()
111
    {
112
        return $this->contact;
113
    }
114
115
    /**
116
     * @param Contact $contact
117
     *
118
     * @return Setting
119
     */
120 1
    public function withContact(Contact $contact)
121
    {
122 1
        $new = clone $this;
123 1
        $new->contact = $contact;
124
125 1
        return $new;
126
    }
127
128
    /**
129
     * @return BusinessAddress
130
     */
131
    public function getBusinessAddress()
132
    {
133
        return $this->businessAddress;
134
    }
135
136
    /**
137
     * @param BusinessAddress $businessAddress
138
     *
139
     * @return Setting
140
     */
141 1
    public function withBusinessAddress(BusinessAddress $businessAddress)
142
    {
143 1
        $new = clone $this;
144 1
        $new->businessAddress = $businessAddress;
145
146 1
        return $new;
147
    }
148
149
    /**
150
     * @return InvoiceAddress
151
     */
152
    public function getInvoiceAddress()
153
    {
154
        return $this->invoiceAddress;
155
    }
156
157
    /**
158
     * @param InvoiceAddress $invoiceAddress
159
     *
160
     * @return Setting
161
     */
162 1
    public function withInvoiceAddress(InvoiceAddress $invoiceAddress)
163
    {
164 1
        $new = clone $this;
165 1
        $new->invoiceAddress = $invoiceAddress;
166
167 1
        return $new;
168
    }
169
170
    /**
171
     * @return VisitingAddress
172
     */
173
    public function getVisitingAddress()
174
    {
175
        return $this->visitingAddress;
176
    }
177
178
    /**
179
     * @param VisitingAddress $visitingAddress
180
     *
181
     * @return Setting
182
     */
183 1
    public function withVisitingAddress(VisitingAddress $visitingAddress)
184
    {
185 1
        $new = clone $this;
186 1
        $new->visitingAddress = $visitingAddress;
187
188 1
        return $new;
189
    }
190
191
    /**
192
     * @return mixed
193
     */
194
    public function getPayment()
195
    {
196
        return $this->payment;
197
    }
198
199
    /**
200
     * @param $payment
201
     *
202
     * @return Setting
203
     */
204 1
    public function withPayment($payment)
205
    {
206 1
        $new = clone $this;
207 1
        $new->payment = $payment;
208
209 1
        return $new;
210
    }
211
212
    /**
213
     * @return mixed
214
     */
215
    public function getTax()
216
    {
217
        return $this->tax;
218
    }
219
220
    /**
221
     * @param $tax
222
     *
223
     * @return Setting
224
     */
225 1
    public function withTax($tax)
226
    {
227 1
        $new = clone $this;
228 1
        $new->tax = $tax;
229
230 1
        return $new;
231
    }
232
233
    /**
234
     * @return mixed
235
     */
236
    public function getBookkeeping()
237
    {
238
        return $this->bookkeeping;
239
    }
240
241
    /**
242
     * @param $bookkeeping
243
     *
244
     * @return Setting
245
     */
246 1
    public function withBookkeeping($bookkeeping)
247
    {
248 1
        $new = clone $this;
249 1
        $new->bookkeeping = $bookkeeping;
250
251 1
        return $new;
252
    }
253
254
    /**
255
     * @return mixed
256
     */
257
    public function getInvoices()
258
    {
259
        return $this->invoices;
260
    }
261
262
    /**
263
     * @param $invoices
264
     *
265
     * @return Setting
266
     */
267 1
    public function withInvoices($invoices)
268
    {
269 1
        $new = clone $this;
270 1
        $new->invoices = $invoices;
271
272 1
        return $new;
273
    }
274
275
    /**
276
     * Create an API response object from the HTTP response from the API server.
277
     *
278
     * @param array $data
279
     *
280
     * @return Setting
281
     */
282 2
    public static function createFromArray(array $data)
283
    {
284 2
        $setting = new self();
285 2
        $setting->name = $data['data']['name'] ?? null;
286 2
        $setting->orgNo = $data['data']['org_no'] ?? null;
287 2
        $setting->contact = Contact::createFromArray($data['data']['contact']);
288 2
        $setting->businessAddress = BusinessAddress::createFromArray($data['data']['address']);
289 2
        $setting->visitingAddress = VisitingAddress::createFromArray($data['data']['visiting_address']);
290 2
        $setting->invoiceAddress = InvoiceAddress::createFromArray($data['data']['invoice_address']);
291 2
        $setting->payment = PaymentSetting::createFromArray($data['data']['payment']);
292 2
        $setting->bookkeeping = BookkeepingSetting::createFromArray($data['data']['bookkeeping']);
293 2
        $setting->invoices = InvoiceDefaults::createFromArray($data['data']['invoices']);
294
295 2
        return $setting;
296
    }
297
298 1
    public function toArray()
299
    {
300 1
        $data = [];
301 1
        if ($this->name !== null) {
302 1
            $data['name'] = $this->name;
303
        }
304 1
        if ($this->orgNo !== null) {
305 1
            $data['org_no'] = $this->orgNo;
306
        }
307 1
        if ($this->contact !== null) {
308 1
            $data['contact'] = $this->contact->toArray();
309
        }
310 1
        if ($this->businessAddress !== null) {
311 1
            $data['address'] = $this->businessAddress->toArray();
312
        }
313 1
        if ($this->invoiceAddress !== null) {
314 1
            $data['invoice_address'] = $this->invoiceAddress->toArray();
315
        }
316 1
        if ($this->visitingAddress !== null) {
317 1
            $data['visiting_address'] = $this->visitingAddress->toArray();
318
        }
319 1
        if ($this->payment !== null) {
320 1
            $data['payment'] = $this->payment->toArray();
321
        }
322 1
        if ($this->tax !== null) {
323 1
            $data['tax'] = $this->tax->toArray();
324
        }
325 1
        if ($this->bookkeeping !== null) {
326 1
            $data['bookkeeping'] = $this->bookkeeping->toArray();
327
        }
328 1
        if ($this->invoices !== null) {
329 1
            $data['invoices'] = $this->invoices->toArray();
330
        }
331
332 1
        return $data;
333
    }
334
}
335