AccountData   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 2
eloc 9
c 2
b 0
f 0
dl 0
loc 23
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A fromResponse() 0 11 1
1
<?php
2
3
namespace Rogierw\RwAcme\DTO;
4
5
use Rogierw\RwAcme\Http\Response;
6
use Rogierw\RwAcme\Support\Url;
7
use Spatie\LaravelData\Data;
8
9
class AccountData extends Data
10
{
11
    public function __construct(
12
        public string $id,
13
        public string $url,
14
        public array $key,
15
        public string $status,
16
        public string $agreement,
17
        public string $createdAt,
18
    ) {
19
    }
20
21
    public static function fromResponse(Response $response): AccountData
22
    {
23
        $url = trim($response->getHeader('location', ''));
24
25
        return new self(
26
            id: Url::extractId($url),
27
            url: $url,
28
            key: $response->getBody()['key'],
29
            status: $response->getBody()['status'],
30
            agreement: $response->getBody()['agreement'] ?? '',
31
            createdAt: $response->getBody()['createdAt']
32
        );
33
    }
34
}
35