Passed
Push — master ( e7e3c4...d0e289 )
by Rogier
01:26
created

AccountData   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 19
c 1
b 0
f 0
dl 0
loc 24
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
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\DataTransferObject\DataTransferObject;
9
10
class AccountData extends DataTransferObject
11
{
12
    public $id;
13
    public $url;
14
    public $key;
15
    public $status;
16
    public $contact;
17
    public $agreement;
18
    public $initialIp;
19
    public $createdAt;
20
21
    public static function fromResponse(Response $response): self
22
    {
23
        $url = trim(Arr::get($response->getRawHeaders(), '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
            'contact'   => $response->getBody()['contact'],
31
            'agreement' => $response->getBody()['agreement'] ?? '',
32
            'initialIp' => $response->getBody()['initialIp'],
33
            'createdAt' => $response->getBody()['createdAt'],
34
        ]);
35
    }
36
}
37