Completed
Push — master ( 5c5133...4bc4b0 )
by Marcin
02:40
created

KrsEntity::__construct()   F

Complexity

Conditions 28
Paths 17425

Size

Total Lines 90
Code Lines 65

Duplication

Lines 14
Ratio 15.56 %

Code Coverage

Tests 24
CRAP Score 224.7846

Importance

Changes 0
Metric Value
dl 14
loc 90
ccs 24
cts 65
cp 0.3691
rs 2.0421
c 0
b 0
f 0
cc 28
eloc 65
nc 17425
nop 2
crap 224.7846

How to fix   Long Method    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
 * MOJEPANSTWO-API
4
 *
5
 * Copyright © 2017 pudelek.org.pl
6
 *
7
 * @license MIT License (MIT)
8
 *
9
 * For the full copyright and license information, please view source file
10
 * that is bundled with this package in the file LICENSE
11
 *
12
 * @author  Marcin Pudełek <[email protected]>
13
 */
14
15
declare (strict_types=1);
16
17
namespace mrcnpdlk\MojePanstwo\Model;
18
19
20
use mrcnpdlk\MojePanstwo\Api;
21
use mrcnpdlk\MojePanstwo\Model\KrsEntity\Companies;
22
use mrcnpdlk\MojePanstwo\Model\KrsEntity\Department;
23
use mrcnpdlk\MojePanstwo\Model\KrsEntity\Partner;
24
use mrcnpdlk\MojePanstwo\Model\KrsEntity\Person;
25
use mrcnpdlk\MojePanstwo\Model\KrsEntity\Pkd;
26
use mrcnpdlk\MojePanstwo\Model\KrsEntity\Share;
27
28
class KrsEntity extends ModelAbstract
29
{
30
    const CONTEXT                    = 'krs_podmioty';
31
    const PULL_NONE                  = 0;
32
    const PULL_COMPANIES             = 1;
33
    const PULL_DEPARTMENTS           = 2;
34
    const PULL_PARTNERS              = 4;
35
    const PULL_PKDS                  = 8;
36
    const PULL_SHARES                = 16;
37
    const PULL_PERSON_REPRESENTATION = 32;
38
    const PULL_PERSON_SUPERVISION    = 64;
39
    const PULL_PERSON_PROXY          = 128;
40
    const PULL_ALL                   = 255;
41
42
43
    /**
44
     * Krs jako int
45
     *
46
     * @var integer
47
     **/
48
    public $id;
49
    /**
50
     * krs
51
     *
52
     * @var string
53
     **/
54
    public $krs;
55
    /**
56
     * nip
57
     *
58
     * @var string|null
59
     **/
60
    public $nip;
61
    /**
62
     * regon
63
     *
64
     * @var string|null
65
     **/
66
    public $regon;
67
    /**
68
     * nazwa
69
     *
70
     * @var string
71
     **/
72
    public $nazwa;
73
    /**
74
     * nazwa_skrocona
75
     *
76
     * @var string
77
     **/
78
    public $nazwa_skrocona;
79
    /**
80
     * adres
81
     *
82
     * @var string
83
     **/
84
    public $adres;
85
    /**
86
     * wojewodztwo_id
87
     *
88
     * @var integer
89
     **/
90
    public $wojewodztwo_id;
91
    /**
92
     * powiat_id
93
     *
94
     * @var integer
95
     **/
96
    public $powiat_id;
97
    /**
98
     * gmina_id
99
     *
100
     * @var integer
101
     **/
102
    public $gmina_id;
103
    /**
104
     * miejscowosc_id
105
     *
106
     * @var integer
107
     **/
108
    public $miejscowosc_id;
109
    /**
110
     * kod_pocztowy_id
111
     *
112
     * @var integer
113
     **/
114
    public $kod_pocztowy_id;
115
    /**
116
     * adres_kod_pocztowy
117
     *
118
     * @var integer
119
     **/
120
    public $adres_kod_pocztowy;
121
    /**
122
     * adres_kraj
123
     *
124
     * @var string
125
     **/
126
    public $adres_kraj;
127
    /**
128
     * adres_lokal
129
     *
130
     * @var string
131
     **/
132
    public $adres_lokal;
133
    /**
134
     * adres_miejscowosc
135
     *
136
     * @var string
137
     **/
138
    public $adres_miejscowosc;
139
    /**
140
     * adres_numer
141
     *
142
     * @var string
143
     **/
144
    public $adres_numer;
145
    /**
146
     * adres_poczta
147
     *
148
     * @var string
149
     **/
150
    public $adres_poczta;
151
    /**
152
     * adres_ulica
153
     *
154
     * @var string
155
     **/
156
    public $adres_ulica;
157
    /**
158
     * siedziba
159
     *
160
     * @var string
161
     **/
162
    public $siedziba;
163
    /**
164
     * cel_dzialania
165
     *
166
     * @var string
167
     **/
168
    public $cel_dzialania;
169
    /**
170
     * data_dokonania_wpisu
171
     *
172
     * @var string
173
     **/
174
    public $data_dokonania_wpisu;
175
    /**
176
     * data_ostatni_wpis
177
     *
178
     * @var string|null
179
     **/
180
    public $data_ostatni_wpis;
181
    /**
182
     * data_rejestracji
183
     *
184
     * @var string
185
     **/
186
    public $data_rejestracji;
187
    /**
188
     * data_sprawdzenia
189
     *
190
     * @var string
191
     **/
192
    public $data_sprawdzenia;
193
    /**
194
     * dotacje_ue_beneficjent_id
195
     *
196
     * @var integer|null
197
     **/
198
    public $dotacje_ue_beneficjent_id;
199
    /**
200
     * email
201
     **/
202
    public $email;
203
    /**
204
     * firma
205
     **/
206
    public $firma;
207
    /**
208
     * forma_prawna_id
209
     *
210
     * @var integer
211
     **/
212
    public $forma_prawna_id;
213
    /**
214
     * forma_prawna_str
215
     *
216
     * @var string
217
     **/
218
    public $forma_prawna_str;
219
    /**
220
     * forma_prawna_typ_id
221
     *
222
     * @var integer
223
     **/
224
    public $forma_prawna_typ_id;
225
    /**
226
     * forma_prawna_typ_str - pole dodaane jako dodatkowe
227
     *
228
     * @var string
229
     **/
230
    public $forma_prawna_typ_str;
231
    /**
232
     * gpw
233
     *
234
     * @var mixed
235
     **/
236
    public $gpw;
237
    /**
238
     * gpw_spolka_id
239
     *
240
     * @var integer|null
241
     **/
242
    public $gpw_spolka_id;
243
    /**
244
     * knf_ostrzezenie_id
245
     *
246
     * @var integer|null
247
     **/
248
    public $knf_ostrzezenie_id;
249
    /**
250
     * liczba_akcji_wszystkich_emisji
251
     *
252
     * @var integer
253
     **/
254
    public $liczba_akcji_wszystkich_emisji;
255
    /**
256
     * liczba_czlonkow_komitetu_zal
257
     *
258
     * @var integer
259
     **/
260
    public $liczba_czlonkow_komitetu_zal;
261
    /**
262
     * liczba_dzialalnosci
263
     *
264
     * @var integer
265
     **/
266
    public $liczba_dzialalnosci;
267
    /**
268
     * liczba_emisji_akcji
269
     *
270
     * @var integer
271
     **/
272
    public $liczba_emisji_akcji;
273
    /**
274
     * liczba_jedynych_akcjonariuszy
275
     *
276
     * @var integer
277
     **/
278
    public $liczba_jedynych_akcjonariuszy;
279
    /**
280
     * liczba_nadzorcow
281
     *
282
     * @var integer
283
     **/
284
    public $liczba_nadzorcow;
285
    /**
286
     * liczba_oddzialow
287
     *
288
     * @var integer
289
     **/
290
    public $liczba_oddzialow;
291
    /**
292
     * liczba_prokurentow
293
     *
294
     * @var integer
295
     **/
296
    public $liczba_prokurentow;
297
    /**
298
     * liczba_reprezentantow
299
     *
300
     * @var integer
301
     **/
302
    public $liczba_reprezentantow;
303
    /**
304
     * liczba_wspolnikow
305
     *
306
     * @var integer
307
     **/
308
    public $liczba_wspolnikow;
309
    /**
310
     * liczba_zmian
311
     *
312
     * @var integer
313
     **/
314
    public $liczba_zmian;
315
    /**
316
     * liczba_zmian_umow
317
     *
318
     * @var integer
319
     **/
320
    public $liczba_zmian_umow;
321
    /**
322
     * nazwa_organu_nadzoru
323
     *
324
     * @var string
325
     **/
326
    public $nazwa_organu_nadzoru;
327
    /**
328
     * nazwa_organu_reprezentacji
329
     *
330
     * @var string
331
     **/
332
    public $nazwa_organu_reprezentacji;
333
    /**
334
     * nieprzedsiebiorca
335
     *
336
     * @var string
337
     * @todo DO wyjasnienia znaczenie pola
338
     **/
339
    public $nieprzedsiebiorca;
340
    /**
341
     * numer_wpisu
342
     *
343
     * @var string
344
     **/
345
    public $numer_wpisu;
346
    /**
347
     * opp
348
     *
349
     * @var string|null
350
     **/
351
    public $opp;
352
    /**
353
     * ostatni_wpis_id
354
     *
355
     * @var integer|null
356
     **/
357
    public $ostatni_wpis_id;
358
    /**
359
     * oznaczenie_sadu
360
     *
361
     * @var string
362
     **/
363
    public $oznaczenie_sadu;
364
    /**
365
     * rejestr
366
     *
367
     * @var string
368
     **/
369
    public $rejestr;
370
    /**
371
     * rejestr_stowarzyszen
372
     *
373
     * @var string
374
     **/
375
    public $rejestr_stowarzyszen;
376
    /**
377
     * sposob_reprezentacji
378
     *
379
     * @var string
380
     **/
381
    public $sposob_reprezentacji;
382
    /**
383
     * sygnatura_akt
384
     *
385
     * @var string
386
     **/
387
    public $sygnatura_akt;
388
    /**
389
     * twitter_account_id
390
     *
391
     * @var string
392
     **/
393
    public $twitter_account_id;
394
    /**
395
     * umowa_spolki_cywilnej
396
     *
397
     * @var string|null
398
     **/
399
    public $umowa_spolki_cywilnej;
400
    /**
401
     * wartosc_czesc_kapitalu_wplaconego
402
     *
403
     * @var integer
404
     **/
405
    public $wartosc_czesc_kapitalu_wplaconego;
406
    /**
407
     * wartosc_kapital_docelowy
408
     *
409
     * @var integer
410
     **/
411
    public $wartosc_kapital_docelowy;
412
    /**
413
     * wartosc_kapital_zakladowy
414
     *
415
     * @var integer
416
     **/
417
    public $wartosc_kapital_zakladowy;
418
    /**
419
     * wartosc_nominalna_akcji
420
     *
421
     * @var integer
422
     **/
423
    public $wartosc_nominalna_akcji;
424
    /**
425
     * wartosc_nominalna_podwyzszenia_kapitalu
426
     *
427
     * @var integer
428
     **/
429
    public $wartosc_nominalna_podwyzszenia_kapitalu;
430
    /**
431
     * wczesniejsza_rejestracja_str
432
     *
433
     * @var string
434
     **/
435
    public $wczesniejsza_rejestracja_str;
436
    /**
437
     * www
438
     *
439
     * @var string
440
     **/
441
    public $www;
442
    /**
443
     * wykreslony
444
     *
445
     * @var string
446
     **/
447
    public $wykreslony;
448
    /**
449
     * @var \mrcnpdlk\MojePanstwo\Model\KrsEntity\Pkd[]
450
     */
451
    public $dzialalnosci = [];
452
    /**
453
     * @var \mrcnpdlk\MojePanstwo\Model\KrsEntity\Share[]
454
     */
455
    public $emisje_akcji = [];
456
    /**
457
     * @var \mrcnpdlk\MojePanstwo\Model\KrsEntity\Companies[]
458
     */
459
    public $firmy = [];
460
    /**
461
     * @var \mrcnpdlk\MojePanstwo\Model\KrsEntity\Person
462
     */
463
    public $nadzor = [];
464
    /**
465
     * @var \mrcnpdlk\MojePanstwo\Model\KrsEntity\Person
466
     */
467
    public $prokurenci = [];
468
    /**
469
     * @var \mrcnpdlk\MojePanstwo\Model\KrsEntity\Person
470
     */
471
    public $reprezentacja = [];
472
    /**
473
     * @var \mrcnpdlk\MojePanstwo\Model\KrsEntity\Partner
474
     */
475
    public $wspolnicy = [];
476
477
    /**
478
     * @var \mrcnpdlk\MojePanstwo\Model\KrsEntity\Department
479
     */
480
    public $oddzialy = [];
481
482 1
    public function __construct(\stdClass $oData = null, \stdClass $oLayers = null)
483
    {
484 1
        parent::__construct($oData);
485 1
        if ($oData) {
486 1
            $this->id                        = $this->convertToId($this->id);
487 1
            $this->wojewodztwo_id            = $this->convertToId($this->wojewodztwo_id);
488 1
            $this->powiat_id                 = $this->convertToId($this->powiat_id);
489 1
            $this->gmina_id                  = $this->convertToId($this->gmina_id);
490 1
            $this->miejscowosc_id            = $this->convertToId($this->miejscowosc_id);
491 1
            $this->kod_pocztowy_id           = $this->convertToId($this->kod_pocztowy_id);
492 1
            $this->forma_prawna_id           = $this->convertToId($this->forma_prawna_id);
493 1
            $this->forma_prawna_typ_id       = $this->convertToId($this->forma_prawna_typ_id);
494 1
            $this->gpw_spolka_id             = $this->convertToId($this->gpw_spolka_id);
495 1
            $this->knf_ostrzezenie_id        = $this->convertToId($this->knf_ostrzezenie_id);
496 1
            $this->dotacje_ue_beneficjent_id = $this->convertToId($this->dotacje_ue_beneficjent_id);
497 1
            $this->opp                       = $this->convertToId($this->opp);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->convertToId($this->opp) can also be of type integer. However, the property $opp is declared as type string|null. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
498 1
            $this->ostatni_wpis_id           = $this->convertToId($this->ostatni_wpis_id);
499 1
            $this->regon                     = $this->regon === '0' ? null : $this->regon;
500 1
            $this->data_sprawdzenia          = $this->data_sprawdzenia ? (new \DateTime($this->data_sprawdzenia))->format('Y-m-d H:i:s') : null;
501 1
            switch ($this->forma_prawna_typ_id) {
502 1
                case 1:
503 1
                    $this->forma_prawna_typ_str = 'Organizacje biznesowe';
504 1
                    break;
505
                case 2:
506
                    $this->forma_prawna_typ_str = 'Organizacje pozarządowe';
507
                    break;
508
                case 3:
509
                    $this->forma_prawna_typ_str = 'Samodzielne publiczne zakłady opieki zdrowotnej';
510
                    break;
511
                default:
512
                    $this->forma_prawna_typ_str = null;
513
            }
514
        }
515 1
        if ($oLayers) {
516
            if (isset($oLayers->dzialalnosci)) {
517
                foreach ($oLayers->dzialalnosci as $i) {
518
                    $this->dzialalnosci[] = new Pkd($i);
519
                }
520
            }
521
            if (isset($oLayers->emisje_akcji)) {
522
                foreach ($oLayers->emisje_akcji as $i) {
523
                    $this->emisje_akcji[] = new Share($i);
524
                }
525
            }
526
            if (isset($oLayers->firmy)) {
527
                foreach ($oLayers->firmy as $i) {
528
                    $this->firmy[] = new Companies($i);
529
                }
530
            }
531
            if (isset($oLayers->nadzor)) {
532
                foreach ($oLayers->nadzor as $i) {
533
                    $this->nadzor[] = new Person($i);
534
                }
535
            }
536
            if (isset($oLayers->prokurenci)) {
537
                foreach ($oLayers->prokurenci as $i) {
538
                    $this->prokurenci[] = new Person($i);
539
                }
540
            }
541
            if (isset($oLayers->reprezentacja)) {
542
                foreach ($oLayers->reprezentacja as $i) {
543
                    $this->reprezentacja[] = new Person($i);
544
                }
545
            }
546
            if (isset($oLayers->wspolnicy)) {
547
                foreach ($oLayers->wspolnicy as $i) {
548
                    $this->wspolnicy[] = new Partner($i);
549
                }
550
            }
551
            if (isset($oLayers->oddzialy)) {
552
                foreach ($oLayers->oddzialy as $i) {
553
                    $this->oddzialy[] = new Department($i);
554
                }
555
            }
556 View Code Duplication
            if (isset($oLayers->jedynyAkcjonariusz) && !empty($oLayers->jedynyAkcjonariusz)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
557
                Api::getInstance()
558
                   ->getClient()
559
                   ->getLogger()
560
                   ->warning(sprintf('jedynyAkcjonariusz not defined'))
561
                ;
562
            }
563 View Code Duplication
            if (isset($oLayers->komitetZalozycielski) && !empty($oLayers->komitetZalozycielski)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
564
                Api::getInstance()
565
                   ->getClient()
566
                   ->getLogger()
567
                   ->warning(sprintf('komitetZalozycielski not defined'))
568
                ;
569
            }
570
        }
571 1
    }
572
}
573