AccountData::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 0
c 1
b 0
f 0
dl 0
loc 8
rs 10
cc 1
nc 1
nop 6
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