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

OrderData   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Importance

Changes 5
Bugs 1 Features 3
Metric Value
eloc 33
c 5
b 1
f 3
dl 0
loc 71
rs 10
wmc 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A isInvalid() 0 3 1
A fromResponse() 0 20 2
A isNotFinalized() 0 3 1
A isPending() 0 3 1
A isFinalized() 0 3 2
A isValid() 0 3 1
A setCertificateUrl() 0 4 1
A isReady() 0 3 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 OrderData extends DataTransferObject
11
{
12
    public $id;
13
    public $url;
14
    public $status;
15
    public $expires;
16
    public $identifiers;
17
    public $domainValidationUrls;
18
    public $finalizeUrl;
19
    public $accountUrl;
20
    public $certificateUrl;
21
22
    private $finalized = false;
23
24
    public static function fromResponse(Response $response, string $accountUrl = ''): self
25
    {
26
        $url = Arr::get($response->getRawHeaders(), 'Location');
27
28
        if (empty($url)) {
29
            $url = Arr::get($response->getHeaders(), 'url');
30
        }
31
32
        $url = trim(rtrim($url, '?'));
33
34
        return new self([
35
            'id'                   => Url::extractId($url),
36
            'url'                  => $url,
37
            'status'               => $response->getBody()['status'],
38
            'expires'              => $response->getBody()['expires'],
39
            'identifiers'          => $response->getBody()['identifiers'],
40
            'domainValidationUrls' => $response->getBody()['authorizations'],
41
            'finalizeUrl'          => $response->getBody()['finalize'],
42
            'certificateUrl'       => Arr::get($response->getBody(), 'certificate'),
43
            'accountUrl'           => $accountUrl,
44
        ]);
45
    }
46
47
    public function setCertificateUrl(string $url): void
48
    {
49
        $this->certificateUrl = $url;
50
        $this->finalized = true;
51
    }
52
53
    public function isPending(): bool
54
    {
55
        return $this->status === 'pending';
56
    }
57
58
    public function isReady(): bool
59
    {
60
        return $this->status === 'ready';
61
    }
62
63
    public function isValid(): bool
64
    {
65
        return $this->status === 'valid';
66
    }
67
68
    public function isInvalid(): bool
69
    {
70
        return $this->status === 'invalid';
71
    }
72
73
    public function isFinalized(): bool
74
    {
75
        return ($this->finalized || $this->isValid());
76
    }
77
78
    public function isNotFinalized(): bool
79
    {
80
        return !$this->isFinalized();
81
    }
82
}
83