Completed
Push — master ( abba19...1cc20b )
by Dennis
16:52
created

AresRecord::__construct()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 11
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 4

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 11
ccs 10
cts 10
cp 1
rs 9.2
cc 4
eloc 9
nc 8
nop 8
crap 4

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
namespace Defr\Ares;
4
5
use Defr\Justice;
6
use Defr\ValueObject\Person;
7
use Goutte\Client as GouteClient;
8
use GuzzleHttp\Client as GuzzleClient;
9
10
/**
11
 * Class AresRecord.
12
 *
13
 * @author Dennis Fridrich <[email protected]>
14
 */
15
class AresRecord
16
{
17
    /**
18
     * @var int
19
     */
20
    private $companyId;
21
22
    /**
23
     * @var string
24
     */
25
    private $taxId;
26
27
    /**
28
     * @var string
29
     */
30
    private $companyName;
31
32
    /**
33
     * @var string
34
     */
35
    private $street;
36
37
    /**
38
     * @var string
39
     */
40
    private $streetHouseNumber;
41
42
    /**
43
     * @var string
44
     */
45
    private $streetOrientationNumber;
46
47
    /**
48
     * @var string
49
     */
50
    private $town;
51
52
    /**
53
     * @var string
54
     */
55
    private $zip;
56
57
    /**
58
     * @var null|GouteClient
59
     */
60
    protected $client;
61
62
    /**
63
     * AresRecord constructor.
64
     * @param null $companyId
65
     * @param null $taxId
66
     * @param null $companyName
67
     * @param null $street
68
     * @param null $streetHouseNumber
69
     * @param null $streetOrientationNumber
70
     * @param null $town
71
     * @param null $zip
72
     */
73 2
    public function __construct($companyId = null, $taxId = null, $companyName = null, $street = null, $streetHouseNumber = null, $streetOrientationNumber = null, $town = null, $zip = null)
74
    {
75 2
        $this->companyId = $companyId;
76 2
        $this->taxId = !empty($taxId) ? $taxId : null;
77 2
        $this->companyName = $companyName;
78 2
        $this->street = $street;
79 2
        $this->streetHouseNumber = !empty($streetHouseNumber) ? $streetHouseNumber : null;
80 2
        $this->streetOrientationNumber = !empty($streetOrientationNumber) ? $streetOrientationNumber : null;
81 2
        $this->town = $town;
82 2
        $this->zip = $zip;
83 2
    }
84
85
    /**
86
     * @return string
87
     */
88
    public function getStreetWithNumbers()
89
    {
90
        return $this->street . ' '
91
        . ($this->streetOrientationNumber
92
            ?
93
            $this->streetHouseNumber . '/' . $this->streetOrientationNumber
94
            :
95
            $this->streetHouseNumber);
96
    }
97
98
    /**
99
     * @return mixed
100
     */
101
    public function __toString()
102
    {
103
        return $this->companyName;
104
    }
105
106
    /**
107
     * @return mixed
108
     */
109 1
    public function getCompanyId()
110
    {
111 1
        return $this->companyId;
112
    }
113
114
    /**
115
     * @return mixed
116
     */
117 1
    public function getTaxId()
118
    {
119 1
        return $this->taxId;
120
    }
121
122
    /**
123
     * @return mixed
124
     */
125 1
    public function getCompanyName()
126
    {
127 1
        return $this->companyName;
128
    }
129
130
    /**
131
     * @return mixed
132
     */
133 1
    public function getStreet()
134
    {
135 1
        return $this->street;
136
    }
137
138
    /**
139
     * @return mixed
140
     */
141 1
    public function getStreetHouseNumber()
142
    {
143 1
        return $this->streetHouseNumber;
144
    }
145
146
    /**
147
     * @return mixed
148
     */
149 1
    public function getStreetOrientationNumber()
150
    {
151 1
        return $this->streetOrientationNumber;
152
    }
153
154
    /**
155
     * @return mixed
156
     */
157 1
    public function getTown()
158
    {
159 1
        return $this->town;
160
    }
161
162
    /**
163
     * @return mixed
164
     */
165 1
    public function getZip()
166
    {
167 1
        return $this->zip;
168
    }
169
170
    /**
171
     * @param GouteClient $client
172
     *
173
     * @return $this
174
     */
175
    public function setClient(GouteClient $client)
176
    {
177
        $this->client = $client;
178
179
        return $this;
180
    }
181
182
    /**
183
     * @return GouteClient
184
     */
185
    public function getClient()
186
    {
187
        if (!$this->client) {
188
            $this->client = new GouteClient();
189
            $this->client->setClient(new GuzzleClient(['verify' => false]));
190
        }
191
192
        return $this->client;
193
    }
194
195
    /**
196
     * @return array|Person[]
197
     */
198
    public function getCompanyPeople()
199
    {
200
        $client = $this->getClient();
201
        $justice = new Justice($client);
202
        $justiceRecord = $justice->findById($this->companyId);
203
        if ($justiceRecord) {
204
            return $justiceRecord->getPeople();
205
        }
206
207
        return [];
208
    }
209
210
    /**
211
     * @param int $companyId
212
     */
213 2
    public function setCompanyId($companyId)
214
    {
215 2
        $this->companyId = $companyId;
216 2
    }
217
218
    /**
219
     * @param string $taxId
220
     */
221 2
    public function setTaxId($taxId)
222
    {
223 2
        $this->taxId = $taxId;
224 2
    }
225
226
    /**
227
     * @param string $companyName
228
     */
229 2
    public function setCompanyName($companyName)
230
    {
231 2
        $this->companyName = $companyName;
232 2
    }
233
234
    /**
235
     * @param string $street
236
     */
237 1
    public function setStreet($street)
238
    {
239 1
        $this->street = $street;
240 1
    }
241
242
    /**
243
     * @param string $streetHouseNumber
244
     */
245 1
    public function setStreetHouseNumber($streetHouseNumber)
246
    {
247 1
        $this->streetHouseNumber = $streetHouseNumber;
248 1
    }
249
250
    /**
251
     * @param string $streetOrientationNumber
252
     */
253 1
    public function setStreetOrientationNumber($streetOrientationNumber)
254
    {
255 1
        $this->streetOrientationNumber = $streetOrientationNumber;
256 1
    }
257
258
    /**
259
     * @param string $town
260
     */
261 1
    public function setTown($town)
262
    {
263 1
        $this->town = $town;
264 1
    }
265
266
    /**
267
     * @param string $zip
268
     */
269 1
    public function setZip($zip)
270
    {
271 1
        $this->zip = $zip;
272 1
    }
273
274
}
275