AbstractResponseModel   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 115
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 28
dl 0
loc 115
ccs 20
cts 20
cp 1
rs 10
c 0
b 0
f 0
wmc 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A expandData() 0 18 6
A clearData() 0 10 3
A __construct() 0 3 1
1
<?php
2
/**
3
 * TERYT-API
4
 *
5
 * Copyright (c) 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
 * @author Marcin Pudełek <[email protected]>
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
use mrcnpdlk\Teryt\Model\Terc;
22
use stdClass;
23
24
/**
25
 * Class AbstractResponseModel
26
 */
27
abstract class AbstractResponseModel
28
{
29
    /**
30
     * Dwuznakowy symbol województwa
31
     *
32
     * @var string
33
     */
34
    public $provinceId;
35
    /**
36
     * Dwuznakowy symbol powiatu
37
     *
38
     * @var string|null
39
     */
40
    public $districtId;
41
    /**
42
     * Dwuznakowy symbol gminy
43
     *
44
     * @var string|null
45
     */
46
    public $communeId;
47
    /**
48
     * Jednoznakowy symbol gminy
49
     *
50
     * @var string|null
51
     */
52
    public $communeTypeId;
53
    /**
54
     * Nazwa województwa
55
     *
56
     * @var string
57
     */
58
    public $provinceName;
59
    /**
60
     * Nazwa powiatu
61
     *
62
     * @var string
63
     */
64
    public $districtName;
65
    /**
66
     * Nazwa gminy
67
     *
68
     * @var string
69
     */
70
    public $communeName;
71
    /**
72
     * Nazwa rodzaju gminy
73
     *
74
     * @var string|null
75
     */
76
    public $communeTypeName;
77
    /**
78
     * Określa datę katalogu dla wskazanego stanu w formacie YYYY-MM-DD
79
     *
80
     * @var string|null
81
     */
82
    public $statusDate;
83
    /**
84
     * Identyfikator gminy wraz z RODZ
85
     *
86
     * @var int
87
     */
88
    public $tercId;
89
90
    /**
91
     * AbstractResponseModel constructor.
92
     *
93
     * @throws \mrcnpdlk\Teryt\Exception
94
     */
95 5
    public function __construct()
96
    {
97 5
        $this->expandData();
98 5
    }
99
100
    /**
101
     * Dociągnięcie informacji na pozostałe pola obiektu
102
     *
103
     * @throws \mrcnpdlk\Teryt\Exception
104
     *
105
     * @return $this
106
     */
107 5
    public function expandData(): self
108
    {
109 5
        if ($this->tercId) {
110 1
            $oTerc               = new Terc($this->tercId);
111 1
            $this->provinceId    = $oTerc->getProvinceId();
112 1
            $this->districtId    = $oTerc->getDistrictId();
113 1
            $this->communeId     = $oTerc->getCommuneId();
114 1
            $this->communeTypeId = $oTerc->getCommuneTypeId();
115
        } else {
116 5
            if ($this->provinceId && $this->districtId && $this->communeId && $this->communeTypeId) {
117 3
                $oTerc        = (new Terc())->setIds($this->provinceId, $this->districtId, $this->communeId, $this->communeTypeId);
118 3
                $this->tercId = $oTerc->getTercId();
119
            }
120
        }
121
122 5
        $this->clearData();
123
124 5
        return $this;
125
    }
126
127
    /**
128
     * Clearing empty value
129
     *
130
     * @return $this
131
     */
132 5
    public function clearData(): self
133
    {
134
        //clearing data
135 5
        foreach (get_object_vars($this) as $prop => $value) {
136 5
            if ('' === $value) {
137 1
                $this->{$prop} = null;
138
            }
139
        }
140
141 5
        return $this;
142
    }
143
}
144