Authorization::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 6
c 0
b 0
f 0
dl 0
loc 11
rs 10
cc 1
nc 1
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the LetsEncrypt ACME client.
7
 *
8
 * @author    Ivanov Aleksandr <[email protected]>
9
 * @copyright 2019-2020
10
 * @license   https://github.com/misantron/letsencrypt-client/blob/master/LICENSE MIT License
11
 */
12
13
namespace LetsEncrypt\Entity;
14
15
use LetsEncrypt\Exception\ChallengeException;
16
17
final class Authorization extends Entity
18
{
19
    use UrlAwareTrait;
20
21
    /**
22
     * @var array
23
     */
24
    protected $identifier;
25
26
    /**
27
     * @var string
28
     */
29
    public $expires;
30
31
    /**
32
     * @var Challenge[]
33
     */
34
    protected $challenges;
35
36
    /**
37
     * @var bool
38
     */
39
    public $wildcard;
40
41
    public function __construct(array $data, string $url)
42
    {
43
        $this->wildcard = false;
44
45
        $data['challenges'] = array_map(static function (array $entry) {
46
            return new Challenge($entry);
47
        }, $data['challenges']);
48
49
        parent::__construct($data);
50
51
        $this->url = $url;
52
    }
53
54
    /**
55
     * @throws ChallengeException
56
     */
57
    public function getHttpChallenge(): Challenge
58
    {
59
        foreach ($this->challenges as $challenge) {
60
            if ($challenge->isHttp()) {
61
                return $challenge;
62
            }
63
        }
64
        throw new ChallengeException('http');
65
    }
66
67
    /**
68
     * @throws ChallengeException
69
     */
70
    public function getDnsChallenge(): Challenge
71
    {
72
        foreach ($this->challenges as $challenge) {
73
            if ($challenge->isDns()) {
74
                return $challenge;
75
            }
76
        }
77
        throw new ChallengeException('dns');
78
    }
79
80
    public function getIdentifierValue(): string
81
    {
82
        return $this->identifier['value'];
83
    }
84
85
    public function isIdentifierValueEqual(string $identifier): bool
86
    {
87
        return $this->identifier['value'] === $identifier;
88
    }
89
}
90