KrsEntityType::__construct()   B
last analyzed

Complexity

Conditions 5
Paths 5

Size

Total Lines 21
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 6.7458

Importance

Changes 0
Metric Value
dl 0
loc 21
ccs 10
cts 17
cp 0.5881
rs 8.7624
c 0
b 0
f 0
cc 5
eloc 17
nc 5
nop 1
crap 6.7458
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
/**
16
 * Created by Marcin.
17
 * Date: 28.10.2017
18
 * Time: 19:59
19
 */
20
declare (strict_types=1);
21
22
namespace mrcnpdlk\MojePanstwo\Model;
23
24
25
/**
26
 * Class KrsEntityType
27
 *
28
 * @package mrcnpdlk\MojePanstwo\Model
29
 */
30
class KrsEntityType extends ModelAbstract
31
{
32
    const CONTEXT = 'krs_formy_prawne';
33
34
    /**
35
     * ID
36
     *
37
     * @var integer
38
     **/
39
    public $id;
40
    /**
41
     * Nazwa
42
     *
43
     * @var string
44
     **/
45
    public $nazwa;
46
    /**
47
     * krs
48
     *
49
     * @var string
50
     **/
51
    public $typ_id;
52
    /**
53
     * @var string
54
     */
55
    public $typ_nazwa;
56
57
    /**
58
     * KrsEntityType constructor.
59
     *
60
     * @param \stdClass|null $oData
61
     *
62
     * @throws \mrcnpdlk\MojePanstwo\Exception
63
     */
64 1
    public function __construct(\stdClass $oData = null)
65
    {
66 1
        parent::__construct($oData);
67 1
        if ($oData) {
68 1
            $this->id     = $this->convertToId($this->id);
69 1
            $this->typ_id = $this->convertToId($this->typ_id);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->convertToId($this->typ_id) can also be of type integer. However, the property $typ_id is declared as type string. 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...
70 1
            switch ($this->typ_id) {
71 1
                case 1:
72 1
                    $this->typ_nazwa = 'Organizacje biznesowe';
73 1
                    break;
74
                case 2:
75
                    $this->typ_nazwa = 'Organizacje pozarządowe';
76
                    break;
77
                case 3:
78
                    $this->typ_nazwa = 'Samodzielne publiczne zakłady opieki zdrowotnej';
79
                    break;
80
                default:
81
                    $this->typ_nazwa = null;
82
            }
83
        }
84 1
    }
85
}
86