1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Spatie\BpostAddressWebservice\Responses; |
4
|
|
|
|
5
|
|
|
use Spatie\BpostAddressWebservice\Address; |
6
|
|
|
use Spatie\BpostAddressWebservice\Issues\Error; |
7
|
|
|
use Spatie\BpostAddressWebservice\Issues\Warning; |
8
|
|
|
use Spatie\BpostAddressWebservice\ValidatedAddress; |
9
|
|
|
|
10
|
|
|
class ValidateAddressesResponse |
11
|
|
|
{ |
12
|
|
|
/** @var array */ |
13
|
|
|
protected $responseBody = []; |
14
|
|
|
|
15
|
|
|
/** @var \Spatie\BpostAddressWebservice\Address */ |
16
|
|
|
protected $originalAddresses = []; |
17
|
|
|
|
18
|
|
|
public function __construct(array $responseBody, array $originalAddresses) |
19
|
|
|
{ |
20
|
|
|
$this->responseBody = $responseBody; |
21
|
|
|
|
22
|
|
|
$this->originalAddresses = $originalAddresses; |
|
|
|
|
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function validatedAddresses(): array |
26
|
|
|
{ |
27
|
|
|
$validationResults = $this->responseBody['ValidateAddressesResponse']['ValidatedAddressResultList']['ValidatedAddressResult'] ?? []; |
28
|
|
|
|
29
|
|
|
return array_map(function (array $validationResult) { |
30
|
|
|
$errors = []; |
31
|
|
|
$warnings = []; |
32
|
|
|
|
33
|
|
|
foreach ($validationResult['Error'] ?? [] as $error) { |
34
|
|
|
if ($error['ErrorSeverity'] === 'warning') { |
35
|
|
|
$warnings[] = new Warning($error['ErrorCode'], lcfirst($error['ComponentRef'])); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
if ($error['ErrorSeverity'] === 'error') { |
39
|
|
|
$errors[] = new Error($error['ErrorCode'], lcfirst($error['ComponentRef'])); |
40
|
|
|
} |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
return new ValidatedAddress( |
44
|
|
|
Address::fromResponse($validationResult['ValidatedAddressList']['ValidatedAddress'][0] ?? []), |
45
|
|
|
$this->originalAddresses[$validationResult['@id']], |
46
|
|
|
$errors, |
47
|
|
|
$warnings |
48
|
|
|
); |
49
|
|
|
}, $validationResults); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function responseBody() : array |
53
|
|
|
{ |
54
|
|
|
return $this->responseBody; |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..