Passed
Push — master ( 199cf7...129662 )
by Rogier
12:20
created

AccountData::fromResponse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 13
rs 9.9332
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Rogierw\RwAcme\DTO;
4
5
use Rogierw\RwAcme\Http\Response;
6
use Rogierw\RwAcme\Support\Arr;
7
use Rogierw\RwAcme\Support\Url;
8
use Spatie\LaravelData\Data;
9
10
class AccountData extends Data
11
{
12
    public function __construct(
13
        public string $id,
14
        public string $url,
15
        public array $key,
16
        public string $status,
17
        public array $contact,
18
        public string $agreement,
19
        public string $initialIp,
20
        public string $createdAt,
21
    ) {}
22
23
    public static function fromResponse(Response $response): AccountData
24
    {
25
        $url = trim(Arr::get($response->getRawHeaders(), 'Location', ''));
26
27
        return new self(
28
            id: Url::extractId($url),
29
            url: $url,
30
            key: $response->getBody()['key'],
31
            status: $response->getBody()['status'],
32
            contact: $response->getBody()['contact'],
33
            agreement: $response->getBody()['agreement'] ?? '',
34
            initialIp: $response->getBody()['initialIp'],
35
            createdAt: $response->getBody()['createdAt']
36
        );
37
    }
38
}
39