Completed
Branch master (ff989f)
by Dennis
05:37 queued 04:28
created

AresRecord::__construct()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 11
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

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

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
    public function __construct($companyId = null, $taxId = null, $companyName = null, $street = null, $streetHouseNumber = null, $streetOrientationNumber = null, $town = null, $zip = null)
74
    {
75
        $this->companyId = $companyId;
76
        $this->taxId = !empty($taxId) ? $taxId : null;
77
        $this->companyName = $companyName;
78
        $this->street = $street;
79
        $this->streetHouseNumber = !empty($streetHouseNumber) ? $streetHouseNumber : null;
80
        $this->streetOrientationNumber = !empty($streetOrientationNumber) ? $streetOrientationNumber : null;
81
        $this->town = $town;
82
        $this->zip = $zip;
83
    }
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
    public function getCompanyId()
110
    {
111
        return $this->companyId;
112
    }
113
114
    /**
115
     * @return mixed
116
     */
117
    public function getTaxId()
118
    {
119
        return $this->taxId;
120
    }
121
122
    /**
123
     * @return mixed
124
     */
125
    public function getCompanyName()
126
    {
127
        return $this->companyName;
128
    }
129
130
    /**
131
     * @return mixed
132
     */
133
    public function getStreet()
134
    {
135
        return $this->street;
136
    }
137
138
    /**
139
     * @return mixed
140
     */
141
    public function getStreetHouseNumber()
142
    {
143
        return $this->streetHouseNumber;
144
    }
145
146
    /**
147
     * @return mixed
148
     */
149
    public function getStreetOrientationNumber()
150
    {
151
        return $this->streetOrientationNumber;
152
    }
153
154
    /**
155
     * @return mixed
156
     */
157
    public function getTown()
158
    {
159
        return $this->town;
160
    }
161
162
    /**
163
     * @return mixed
164
     */
165
    public function getZip()
166
    {
167
        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
    public function setCompanyId($companyId)
214
    {
215
        $this->companyId = $companyId;
216
    }
217
218
    /**
219
     * @param string $taxId
220
     */
221
    public function setTaxId($taxId)
222
    {
223
        $this->taxId = $taxId;
224
    }
225
226
    /**
227
     * @param string $companyName
228
     */
229
    public function setCompanyName($companyName)
230
    {
231
        $this->companyName = $companyName;
232
    }
233
234
    /**
235
     * @param string $street
236
     */
237
    public function setStreet($street)
238
    {
239
        $this->street = $street;
240
    }
241
242
    /**
243
     * @param string $streetHouseNumber
244
     */
245
    public function setStreetHouseNumber($streetHouseNumber)
246
    {
247
        $this->streetHouseNumber = $streetHouseNumber;
248
    }
249
250
    /**
251
     * @param string $streetOrientationNumber
252
     */
253
    public function setStreetOrientationNumber($streetOrientationNumber)
254
    {
255
        $this->streetOrientationNumber = $streetOrientationNumber;
256
    }
257
258
    /**
259
     * @param string $town
260
     */
261
    public function setTown($town)
262
    {
263
        $this->town = $town;
264
    }
265
266
    /**
267
     * @param string $zip
268
     */
269
    public function setZip($zip)
270
    {
271
        $this->zip = $zip;
272
    }
273
274
}
275