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

AccountData   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 11
c 0
b 0
f 0
dl 0
loc 26
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 1
A fromResponse() 0 13 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