Completed
Push — master ( cd7319...abba19 )
by Dennis
09:18
created

AresRecord::getStreetHouseNumber()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
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
     *
65
     * @param int    $companyId
66
     * @param string $taxId
67
     * @param string $companyName
68
     * @param string $street
69
     * @param string $streetHouseNumber
70
     * @param string $streetOrientationNumber
71
     * @param string $town
72
     * @param string $zip
73
     */
74
    public function __construct($companyId, $taxId, $companyName, $street, $streetHouseNumber, $streetOrientationNumber, $town, $zip)
75
    {
76
        $this->companyId = $companyId;
77
        $this->taxId = !empty($taxId) ? $taxId : null;
78
        $this->companyName = $companyName;
79
        $this->street = $street;
80
        $this->streetHouseNumber = !empty($streetHouseNumber) ? $streetHouseNumber : null;
81
        $this->streetOrientationNumber = !empty($streetOrientationNumber) ? $streetOrientationNumber : null;
82
        $this->town = $town;
83
        $this->zip = $zip;
84
    }
85
86
    /**
87
     * @return string
88
     */
89
    public function getStreetWithNumbers()
90
    {
91
        return $this->street.' '
92
        .($this->streetOrientationNumber
93
            ?
94
            $this->streetHouseNumber.'/'.$this->streetOrientationNumber
95
            :
96
            $this->streetHouseNumber);
97
    }
98
99
    /**
100
     * @return mixed
101
     */
102
    public function __toString()
103
    {
104
        return $this->companyName;
105
    }
106
107
    /**
108
     * @return mixed
109
     */
110
    public function getCompanyId()
111
    {
112
        return $this->companyId;
113
    }
114
115
    /**
116
     * @return mixed
117
     */
118
    public function getTaxId()
119
    {
120
        return $this->taxId;
121
    }
122
123
    /**
124
     * @return mixed
125
     */
126
    public function getCompanyName()
127
    {
128
        return $this->companyName;
129
    }
130
131
    /**
132
     * @return mixed
133
     */
134
    public function getStreet()
135
    {
136
        return $this->street;
137
    }
138
139
    /**
140
     * @return mixed
141
     */
142
    public function getStreetHouseNumber()
143
    {
144
        return $this->streetHouseNumber;
145
    }
146
147
    /**
148
     * @return mixed
149
     */
150
    public function getStreetOrientationNumber()
151
    {
152
        return $this->streetOrientationNumber;
153
    }
154
155
    /**
156
     * @return mixed
157
     */
158
    public function getTown()
159
    {
160
        return $this->town;
161
    }
162
163
    /**
164
     * @return mixed
165
     */
166
    public function getZip()
167
    {
168
        return $this->zip;
169
    }
170
171
    /**
172
     * @param GouteClient $client
173
     *
174
     * @return $this
175
     */
176
    public function setClient(GouteClient $client)
177
    {
178
        $this->client = $client;
179
180
        return $this;
181
    }
182
183
    /**
184
     * @return GouteClient
185
     */
186
    public function getClient()
187
    {
188
        if (!$this->client) {
189
            $this->client = new GouteClient();
190
            $this->client->setClient(new GuzzleClient(['verify' => false]));
191
        }
192
193
        return $this->client;
194
    }
195
196
    /**
197
     * @return array|Person[]
198
     */
199
    public function getCompanyPeople()
200
    {
201
        $client = $this->getClient();
202
        $justice = new Justice($client);
203
        $justiceRecord = $justice->findById($this->companyId);
204
        if ($justiceRecord) {
205
            return $justiceRecord->getPeople();
206
        }
207
208
        return [];
209
    }
210
}
211