Completed
Push — master ( c13142...c0435c )
by Tobias
02:34
created

CollectionForElectricityInvoices   B

Complexity

Total Complexity 42

Size/Duplication

Total Lines 416
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 12.8%

Importance

Changes 0
Metric Value
wmc 42
lcom 1
cbo 0
dl 0
loc 416
ccs 16
cts 125
cp 0.128
rs 8.295
c 0
b 0
f 0

28 Methods

Rating   Name   Duplication   Size   Complexity  
A getKommunkod() 0 4 1
A withKommunkod() 0 7 1
A isNaringsidkare() 0 4 1
A withNaringsidkare() 0 7 1
A isAvflyttad() 0 4 1
A withAvflyttad() 0 7 1
A getAvflyttadDatum() 0 4 1
A withAvflyttadDatum() 0 7 1
A isFrankopplad() 0 4 1
A withFrankopplad() 0 7 1
A getFrankoppladDatum() 0 4 1
A withFrankoppladDatum() 0 7 1
A getAnladr() 0 4 1
A withAnladr() 0 7 1
A getNatom() 0 4 1
A withNatom() 0 7 1
A getArsforb() 0 4 1
A withArsforb() 0 7 1
A getAnlid() 0 4 1
A withAnlid() 0 7 1
A getKravmall() 0 4 1
A withKravmall() 0 7 1
A getPlombkod() 0 4 1
A withPlombkod() 0 7 1
A isSlutfaktura() 0 4 1
A withSlutfaktura() 0 7 1
F toArray() 0 48 15
A createFromArray() 0 19 1

How to fix   Complexity   

Complex Class

Complex classes like CollectionForElectricityInvoices often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use CollectionForElectricityInvoices, and based on these observations, apply Extract Interface, too.

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 CollectionForElectricityInvoices implements CreatableFromArray
13
{
14
    /**
15
     * @var int
16
     */
17
    private $kommunkod;
18
19
    /**
20
     * @var bool
21
     */
22
    private $naringsidkare;
23
24
    /**
25
     * @var bool
26
     */
27
    private $avflyttad;
28
29
    /**
30
     * var string $avflyttadDatum.
31
     */
32
    private $avflyttadDatum;
33
34
    /**
35
     * @var bool
36
     */
37
    private $frankopplad;
38
39
    /**
40
     * @var string
41
     */
42
    private $frankoppladDatum;
43
44
    /**
45
     * @var string
46
     */
47
    private $anladr;
48
49
    /**
50
     * @var string
51
     */
52
    private $natom;
53
54
    /**
55
     * @var int
56
     */
57
    private $arsforb;
58
59
    /**
60
     * @var string
61
     */
62
    private $anlid;
63
64
    /**
65
     * @var string
66
     */
67
    private $kravmall;
68
69
    /**
70
     * @var string
71
     */
72
    private $plombkod;
73
74
    /**
75
     * @var bool
76
     */
77
    private $slutfaktura;
78
79
    /**
80
     * @return int
81
     */
82
    public function getKommunkod(): int
83
    {
84
        return $this->kommunkod;
85
    }
86
87
    /**
88
     * @param int $kommunkod
89
     *
90
     * @return CollectionForElectricityInvoices
91
     */
92
    public function withKommunkod(int $kommunkod)
93
    {
94
        $new = clone $this;
95
        $new->kommunkod = $kommunkod;
96
97
        return $new;
98
    }
99
100
    /**
101
     * @return bool
102
     */
103
    public function isNaringsidkare(): bool
104
    {
105
        return $this->naringsidkare;
106
    }
107
108
    /**
109
     * @param bool $naringsidkare
110
     *
111
     * @return CollectionForElectricityInvoices
112
     */
113
    public function withNaringsidkare(bool $naringsidkare)
114
    {
115
        $new = clone $this;
116
        $new->naringsidkare = $naringsidkare;
117
118
        return $new;
119
    }
120
121
    /**
122
     * @return bool
123
     */
124
    public function isAvflyttad(): bool
125
    {
126
        return $this->avflyttad;
127
    }
128
129
    /**
130
     * @param bool $avflyttad
131
     *
132
     * @return CollectionForElectricityInvoices
133
     */
134
    public function withAvflyttad(bool $avflyttad)
135
    {
136
        $new = clone $this;
137
        $new->avflyttad = $avflyttad;
138
139
        return $new;
140
    }
141
142
    /**
143
     * @return mixed
144
     */
145
    public function getAvflyttadDatum()
146
    {
147
        return $this->avflyttadDatum;
148
    }
149
150
    /**
151
     * @param mixed $avflyttadDatum
152
     *
153
     * @return CollectionForElectricityInvoices
154
     */
155
    public function withAvflyttadDatum($avflyttadDatum)
156
    {
157
        $new = clone $this;
158
        $new->avflyttadDatum = $avflyttadDatum;
159
160
        return $new;
161
    }
162
163
    /**
164
     * @return bool
165
     */
166
    public function isFrankopplad(): bool
167
    {
168
        return $this->frankopplad;
169
    }
170
171
    /**
172
     * @param bool $frankopplad
173
     *
174
     * @return CollectionForElectricityInvoices
175
     */
176
    public function withFrankopplad(bool $frankopplad)
177
    {
178
        $new = clone $this;
179
        $new->frankopplad = $frankopplad;
180
181
        return $new;
182
    }
183
184
    /**
185
     * @return string
186
     */
187
    public function getFrankoppladDatum(): string
188
    {
189
        return $this->frankoppladDatum;
190
    }
191
192
    /**
193
     * @param string $frankoppladDatum
194
     *
195
     * @return CollectionForElectricityInvoices
196
     */
197
    public function withFrankoppladDatum(string $frankoppladDatum)
198
    {
199
        $new = clone $this;
200
        $new->frankoppladDatum = $frankoppladDatum;
201
202
        return $new;
203
    }
204
205
    /**
206
     * @return string
207
     */
208
    public function getAnladr(): string
209
    {
210
        return $this->anladr;
211
    }
212
213
    /**
214
     * @param string $anladr
215
     *
216
     * @return CollectionForElectricityInvoices
217
     */
218
    public function withAnladr(string $anladr)
219
    {
220
        $new = clone $this;
221
        $new->anladr = $anladr;
222
223
        return $new;
224
    }
225
226
    /**
227
     * @return string
228
     */
229
    public function getNatom(): string
230
    {
231
        return $this->natom;
232
    }
233
234
    /**
235
     * @param string $natom
236
     *
237
     * @return CollectionForElectricityInvoices
238
     */
239
    public function withNatom(string $natom)
240
    {
241
        $new = clone $this;
242
        $new->natom = $natom;
243
244
        return $new;
245
    }
246
247
    /**
248
     * @return int
249
     */
250
    public function getArsforb(): int
251
    {
252
        return $this->arsforb;
253
    }
254
255
    /**
256
     * @param int $arsforb
257
     *
258
     * @return CollectionForElectricityInvoices
259
     */
260
    public function withArsforb(int $arsforb)
261
    {
262
        $new = clone $this;
263
        $new->arsforb = $arsforb;
264
265
        return $new;
266
    }
267
268
    /**
269
     * @return string
270
     */
271
    public function getAnlid(): string
272
    {
273
        return $this->anlid;
274
    }
275
276
    /**
277
     * @param string $anlid
278
     *
279
     * @return CollectionForElectricityInvoices
280
     */
281
    public function withAnlid(string $anlid)
282
    {
283
        $new = clone $this;
284
        $new->anlid = $anlid;
285
286
        return $new;
287
    }
288
289
    /**
290
     * @return string
291
     */
292
    public function getKravmall(): string
293
    {
294
        return $this->kravmall;
295
    }
296
297
    /**
298
     * @param string $kravmall
299
     *
300
     * @return CollectionForElectricityInvoices
301
     */
302
    public function withKravmall(string $kravmall)
303
    {
304
        $new = clone $this;
305
        $new->kravmall = $kravmall;
306
307
        return $new;
308
    }
309
310
    /**
311
     * @return string
312
     */
313
    public function getPlombkod(): string
314
    {
315
        return $this->plombkod;
316
    }
317
318
    /**
319
     * @param string $plombkod
320
     *
321
     * @return CollectionForElectricityInvoices
322
     */
323
    public function withPlombkod(string $plombkod)
324
    {
325
        $new = clone $this;
326
        $new->plombkod = $plombkod;
327
328
        return $new;
329
    }
330
331
    /**
332
     * @return bool
333
     */
334
    public function isSlutfaktura(): bool
335
    {
336
        return $this->slutfaktura;
337
    }
338
339
    /**
340
     * @param bool $slutfaktura
341
     *
342
     * @return CollectionForElectricityInvoices
343
     */
344
    public function withSlutfaktura(bool $slutfaktura)
345
    {
346
        $new = clone $this;
347
        $new->slutfaktura = $slutfaktura;
348
349
        return $new;
350
    }
351
352
    public function toArray()
353
    {
354
        $data = [];
355
        if ($this->kommunkod !== null) {
356
            $data['kommunkod'] = $this->kommunkod;
357
        }
358
        if ($this->naringsidkare !== null) {
359
            $data['naringsidkare'] = $this->naringsidkare ?? null;
360
        }
361
        if ($this->avflyttad !== null) {
362
            $data['our_reference'] = $this->ourReference ?? null;
0 ignored issues
show
Bug introduced by Ibrahimhizeoui
The property ourReference does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
363
        }
364
        if ($this->avflyttad !== null) {
365
            $data['your_reference'] = $this->avflyttad ?? null;
366
        }
367
        if ($this->avflyttadDatum !== null) {
368
            $data['shipping_date'] = $this->avflyttadDatum;
369
        }
370
        if ($this->frankopplad !== null) {
371
            $data['delivery_date'] = $this->frankopplad;
372
        }
373
        if ($this->frankoppladDatum !== null) {
374
            $data['frankoppladDatum'] = $this->frankoppladDatum;
375
        }
376
        if ($this->anladr !== null) {
377
            $data['message'] = $this->anladr;
378
        }
379
        if ($this->natom !== null) {
380
            $data['natom'] = $this->natom;
381
        }
382
        if ($this->arsforb !== null) {
383
            $data['arsforb'] = $this->arsforb;
384
        }
385
        if ($this->anlid !== null) {
386
            $data['anlid'] = $this->anlid;
387
        }
388
        if ($this->kravmall !== null) {
389
            $data['kravmall'] = $this->kravmall;
390
        }
391
        if ($this->plombkod !== null) {
392
            $data['plombkod'] = $this->plombkod;
393
        }
394
        if ($this->slutfaktura !== null) {
395
            $data['slutfaktura'] = $this->slutfaktura;
396
        }
397
398
        return $data;
399
    }
400
401
    /**
402
     * Create an API response object from the HTTP response from the API server.
403
     *
404
     * @param array $data
405
     *
406
     * @return self
407
     */
408 3
    public static function createFromArray(array $data)
409
    {
410 3
        $collection = new self();
411 3
        $collection->kommunkod = $data['kommunkod'] ?? null;
412 3
        $collection->slutfaktura = $data['slutfaktura'] ?? null;
413 3
        $collection->kravmall = $data['kravmall'] ?? null;
414 3
        $collection->frankopplad = $data['frankopplad'] ?? null;
415 3
        $collection->arsforb = $data['arsforb'] ?? null;
416 3
        $collection->plombkod = $data['plombkod'] ?? null;
417 3
        $collection->natom = $data['natom'] ?? null;
418 3
        $collection->avflyttadDatum = $data['avflyttad_datum'] ?? null;
419 3
        $collection->frankoppladDatum = $data['frankopplad_datum'] ?? null;
420 3
        $collection->anladr = $data['anladr'] ?? null;
421 3
        $collection->anlid = $data['anlid'] ?? null;
422 3
        $collection->avflyttad = $data['avflyttad'] ?? null;
423 3
        $collection->naringsidkare = $data['naringsidkare'] ?? null;
424
425 3
        return $collection;
426
    }
427
}
428