GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

ValidateAddressesResponse::validatedAddresses()   A
last analyzed

Complexity

Conditions 4
Paths 1

Size

Total Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 26
rs 9.504
c 0
b 0
f 0
cc 4
nc 1
nop 0
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;
0 ignored issues
show
Documentation Bug introduced by
It seems like $originalAddresses of type array is incompatible with the declared type object<Spatie\BpostAddressWebservice\Address> of property $originalAddresses.

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..

Loading history...
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