Passed
Branch master (88d0d9)
by Marcin
04:10 queued 01:30
created

AbstractResponseModel   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 113
Duplicated Lines 0 %

Test Coverage

Coverage 75%

Importance

Changes 0
Metric Value
dl 0
loc 113
ccs 15
cts 20
cp 0.75
rs 10
c 0
b 0
f 0
wmc 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A clearData() 0 10 3
A __construct() 0 3 1
B expandData() 0 18 6
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
 *
12
 * @author Marcin Pudełek <[email protected]>
13
 *
14
 */
15
16
/**
17
 * Created by Marcin Pudełek <[email protected]>
18
 * Date: 06.09.2017
19
 */
20
21
namespace mrcnpdlk\Teryt\ResponseModel\Territory;
22
23
24
use mrcnpdlk\Teryt\Model\Terc;
25
26
/**
27
 * Class AbstractResponseModel
28
 *
29
 * @package mrcnpdlk\Teryt\ResponseModel\Territory
30
 */
31
abstract class AbstractResponseModel
32
{
33
    /**
34
     * Dwuznakowy symbol województwa
35
     *
36
     * @var string
37
     */
38
    public $provinceId;
39
    /**
40
     * Dwuznakowy symbol powiatu
41
     *
42
     * @var string|null
43
     */
44
    public $districtId;
45
    /**
46
     * Dwuznakowy symbol gminy
47
     *
48
     * @var string|null
49
     */
50
    public $communeId;
51
    /**
52
     * Jednoznakowy symbol gminy
53
     *
54
     * @var string|null
55
     */
56
    public $communeTypeId;
57
    /**
58
     * Nazwa województwa
59
     *
60
     * @var string
61
     */
62
    public $provinceName;
63
    /**
64
     * Nazwa powiatu
65
     *
66
     * @var string
67
     */
68
    public $districtName;
69
    /**
70
     * Nazwa gminy
71
     *
72
     * @var string
73
     */
74
    public $communeName;
75
    /**
76
     * Nazwa rodzaju gminy
77
     *
78
     * @var string|null
79
     */
80
    public $communeTypeName;
81
    /**
82
     * Określa datę katalogu dla wskazanego stanu w formacie YYYY-MM-DD
83
     *
84
     * @var string
85
     */
86
    public $statusDate;
87
    /**
88
     * Identyfikator gminy wraz z RODZ
89
     *
90
     * @var integer
91
     */
92
    public $tercId;
93
94
    /**
95
     * AbstractResponseModel constructor.
96
     *
97
     * @param \stdClass|null $oData
98
     */
99 2
    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

99
    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...
100
    {
101 2
        $this->expandData();
102 2
    }
103
104
    /**
105
     * Dociągnięcie informacji na pozostałe pola obiektu
106
     *
107
     * @return $this
108
     */
109 2
    public function expandData()
110
    {
111 2
        if ($this->tercId) {
112
            $oTerc               = new Terc($this->tercId);
113
            $this->provinceId    = $oTerc->getProvinceId();
114
            $this->districtId    = $oTerc->getDistrictId();
115
            $this->communeId     = $oTerc->getCommuneId();
116
            $this->communeTypeId = $oTerc->getCommuneTypeId();
117
        } else {
118 2
            if ($this->provinceId && $this->districtId && $this->communeId && $this->communeTypeId) {
0 ignored issues
show
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->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->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...
119 1
                $oTerc        = (new Terc())->setIds($this->provinceId, $this->districtId, $this->communeId, $this->communeTypeId);
120 1
                $this->tercId = $oTerc->getTercId();
121
            }
122
        }
123
124 2
        $this->clearData();
125
126 2
        return $this;
127
    }
128
129
    /**
130
     * Clearing empty value
131
     *
132
     * @return $this
133
     */
134 2
    public function clearData()
135
    {
136
        //clearing data
137 2
        foreach (get_object_vars($this) as $prop => $value) {
138 2
            if ($value === '') {
139 2
                $this->{$prop} = null;
140
            }
141
        }
142
143 2
        return $this;
144
    }
145
}
146