Completed
Push — master ( a8b0ff...93e3c3 )
by Dennis
8s
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 1
Bugs 0 Features 0
Metric Value
c 1
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 int    $companyId
65
     * @param string $taxId
66
     * @param string $companyName
67
     * @param string $street
68
     * @param string $streetHouseNumber
69
     * @param string $streetOrientationNumber
70
     * @param string $town
71
     * @param string $zip
72
     */
73 1
    public function __construct($companyId, $taxId, $companyName, $street, $streetHouseNumber, $streetOrientationNumber, $town, $zip)
74
    {
75 1
        $this->companyId = $companyId;
76 1
        $this->taxId = !empty($taxId) ? $taxId : null;
77 1
        $this->companyName = $companyName;
78 1
        $this->street = $street;
79 1
        $this->streetHouseNumber = !empty($streetHouseNumber) ? $streetHouseNumber : null;
80 1
        $this->streetOrientationNumber = !empty($streetOrientationNumber) ? $streetOrientationNumber : null;
81 1
        $this->town = $town;
82 1
        $this->zip = $zip;
83 1
    }
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
     * @return $this
173
     */
174
    public function setClient(GouteClient $client)
175
    {
176
        $this->client = $client;
177
178
        return $this;
179
    }
180
181
    /**
182
     * @return GouteClient
183
     */
184
    public function getClient()
185
    {
186
        if (!$this->client) {
187
            $this->client = new GouteClient();
188
            $this->client->setClient(new GuzzleClient(['verify' => false]));
189
        }
190
191
        return $this->client;
192
    }
193
194
    /**
195
     * @return array|Person[]
196
     */
197
    public function getCompanyPeople()
198
    {
199
        $client = $this->getClient();
200
        $justice = new Justice($client);
201
        $justiceRecord = $justice->findById($this->companyId);
202
        if ($justiceRecord) {
203
            return $justiceRecord->getPeople();
204
        }
205
206
        return [];
207
    }
208
}
209