Completed
Push — master ( 84750e...bb7498 )
by Marcin
02:41
created

AbstractResponseModel::expandData()   B

Complexity

Conditions 6
Paths 3

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 8.8571
c 0
b 0
f 0
cc 6
eloc 12
nc 3
nop 0
1
<?php
2
/**
3
 * TERYT-API
4
 *
5
 * Copyright (c) 2017 pudelek.org.pl
6
 *
7
 * For the full copyright and license information, please view source file
8
 * that is bundled with this package in the file LICENSE
9
 *
10
 * Author Marcin Pudełek <[email protected]>
11
 *
12
 */
13
14
/**
15
 * Created by Marcin Pudełek <[email protected]>
16
 * Date: 06.09.2017
17
 */
18
19
namespace mrcnpdlk\Teryt\ResponseModel\Territory;
20
21
22
use mrcnpdlk\Teryt\Model\Terc;
23
24
/**
25
 * Class AbstractResponseModel
26
 *
27
 * @package mrcnpdlk\Teryt\ResponseModel\Territory
28
 */
29
abstract class AbstractResponseModel
30
{
31
    /**
32
     * Dwuznakowy symbol województwa
33
     *
34
     * @var string
35
     */
36
    public $provinceId;
37
    /**
38
     * Dwuznakowy symbol powiatu
39
     *
40
     * @var string|null
41
     */
42
    public $districtId;
43
    /**
44
     * Dwuznakowy symbol gminy
45
     *
46
     * @var string|null
47
     */
48
    public $communeId;
49
    /**
50
     * Jednoznakowy symbol gminy
51
     *
52
     * @var string|null
53
     */
54
    public $communeTypeId;
55
    /**
56
     * Nazwa województwa
57
     *
58
     * @var string
59
     */
60
    public $provinceName;
61
    /**
62
     * Nazwa powiatu
63
     *
64
     * @var string
65
     */
66
    public $districtName;
67
    /**
68
     * Nazwa gminy
69
     *
70
     * @var string
71
     */
72
    public $communeName;
73
    /**
74
     * Nazwa rodzaju gminy
75
     *
76
     * @var string|null
77
     */
78
    public $communeTypeName;
79
    /**
80
     * Określa datę katalogu dla wskazanego stanu w formacie YYYY-MM-DD
81
     *
82
     * @var string
83
     */
84
    public $statusDate;
85
    /**
86
     * Identyfikator gminy wraz z RODZ
87
     *
88
     * @var integer
89
     */
90
    public $tercId;
91
92
    /**
93
     * AbstractResponseModel constructor.
94
     *
95
     * @param \stdClass|null $oData
96
     */
97
    public function __construct(\stdClass $oData = null)
0 ignored issues
show
Unused Code introduced by
The parameter $oData is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

97
    public function __construct(/** @scrutinizer ignore-unused */ \stdClass $oData = null)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
98
    {
99
        $this->expandData();
100
    }
101
102
    /**
103
     * Dociągnięcie informacji na pozostałe pola obiektu
104
     *
105
     * @return $this
106
     */
107
    public function expandData()
108
    {
109
        if ($this->tercId) {
110
            $oTerc               = new Terc($this->tercId);
111
            $this->provinceId    = $oTerc->getProvinceId();
112
            $this->districtId    = $oTerc->getDistrictId();
113
            $this->communeId     = $oTerc->getCommuneId();
114
            $this->communeTypeId = $oTerc->getCommuneTypeId();
115
        } else {
116
            if ($this->provinceId && $this->districtId && $this->communeId && $this->communeTypeId) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->communeId of type null|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
Bug Best Practice introduced by
The expression $this->districtId of type null|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
Bug Best Practice introduced by
The expression $this->communeTypeId of type null|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
117
                $oTerc        = (new Terc())->setIds($this->provinceId, $this->districtId, $this->communeId, $this->communeTypeId);
118
                $this->tercId = $oTerc->getTercId();
119
            }
120
        }
121
122
        $this->clearData();
123
124
        return $this;
125
    }
126
127
    /**
128
     * Clearing empty value
129
     *
130
     * @return $this
131
     */
132
    public function clearData()
133
    {
134
        //clearing data
135
        foreach (get_object_vars($this) as $prop => $value) {
136
            if ($value === '') {
137
                $this->{$prop} = null;
138
            }
139
        }
140
141
        return $this;
142
    }
143
}
144