|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Spatie\BpostAddressWebservice; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* @property string streetName |
|
7
|
|
|
* @property string streetNumber |
|
8
|
|
|
* @property string boxNumber |
|
9
|
|
|
* @property string postalCode |
|
10
|
|
|
* @property string municipalityName |
|
11
|
|
|
* @property string country |
|
12
|
|
|
* @property array issues |
|
13
|
|
|
*/ |
|
14
|
|
|
class ValidatedAddress |
|
15
|
|
|
{ |
|
16
|
|
|
/** @var \Spatie\BpostAddressWebservice\Address */ |
|
17
|
|
|
public $validatedAddress; |
|
18
|
|
|
|
|
19
|
|
|
/** @var \Spatie\BpostAddressWebservice\Address */ |
|
20
|
|
|
public $originalAddress; |
|
21
|
|
|
|
|
22
|
|
|
/** @var \Spatie\BpostAddressWebservice\Issues\Error[] */ |
|
23
|
|
|
public $errors; |
|
24
|
|
|
|
|
25
|
|
|
/** @var \Spatie\BpostAddressWebservice\Issues\Warning[] */ |
|
26
|
|
|
public $warnings; |
|
27
|
|
|
|
|
28
|
|
|
public function __construct( |
|
29
|
|
|
Address $validatedAddress, |
|
30
|
|
|
Address $originalAddress, |
|
31
|
|
|
array $errors, |
|
32
|
|
|
array $warnings |
|
33
|
|
|
) { |
|
34
|
|
|
$this->validatedAddress = $validatedAddress; |
|
35
|
|
|
$this->originalAddress = $originalAddress; |
|
36
|
|
|
|
|
37
|
|
|
$this->errors = $errors; |
|
38
|
|
|
$this->warnings = $warnings; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function __get(string $key) |
|
42
|
|
|
{ |
|
43
|
|
|
if ($key === 'issues') { |
|
44
|
|
|
return $this->issues; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
return $this->toArray()[$key]; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function hasErrors(): bool |
|
51
|
|
|
{ |
|
52
|
|
|
return count($this->errors) > 0; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function hasWarnings(): bool |
|
56
|
|
|
{ |
|
57
|
|
|
return count($this->warnings) > 0; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function hasIssues(): bool |
|
61
|
|
|
{ |
|
62
|
|
|
return $this->hasWarnings() || $this->hasErrors(); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function issues(): array |
|
66
|
|
|
{ |
|
67
|
|
|
return array_merge($this->warnings, $this->errors); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function originalAddress(): Address |
|
71
|
|
|
{ |
|
72
|
|
|
return $this->originalAddress; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
public function toArray(): array |
|
76
|
|
|
{ |
|
77
|
|
|
return $this->validatedAddress->toArray(); |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|