Get::getChallenge()   A
last analyzed

Complexity

Conditions 5
Paths 4

Size

Total Lines 29
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 15
dl 0
loc 29
ccs 0
cts 14
cp 0
rs 9.4555
c 3
b 0
f 0
cc 5
nc 4
nop 1
crap 30
1
<?php
2
3
namespace LE_ACME2\Response\Authorization;
4
5
use LE_ACME2\Response\Authorization\Struct;
6
7
class Get extends AbstractAuthorization {
8
9
    public function getIdentifier() : Struct\Identifier {
10
11
        return new Struct\Identifier(
12
            $this->_raw->body['identifier']['type'],
13
            $this->_raw->body['identifier']['value']
14
        );
15
    }
16
17
    public function getStatus() : string {
18
        return $this->_raw->body['status'];
19
    }
20
21
    public function getExpires() : string {
22
        return $this->_raw->body['expires'];
23
    }
24
25 1
    public function getChallenges() : array {
26 1
        return $this->_raw->body['challenges'];
27
    }
28
29
    public function getChallenge(string $type) : ?Struct\Challenge {
30
31
        foreach($this->getChallenges() as $challenge) {
32
33
            if($type == $challenge['type']) {
34
35
                $error = null;
36
                if(isset($challenge[ 'error' ]) && $challenge[ 'error' ] != "") {
37
                    $error = new Struct\ChallengeError(
38
                        $challenge[ 'error' ][ 'type' ],
39
                        $challenge[ 'error' ][ 'detail' ],
40
                        $challenge[ 'error' ][ 'status' ],
41
                    );
42
                }
43
44
                return new Struct\Challenge(
45
                    $challenge[ 'type' ],
46
                    $challenge[ 'status' ],
47
                    $challenge[ 'url' ],
48
                    $challenge[ 'token' ],
49
                    $error,
50
                );
51
            }
52
        }
53
54
        // There is not a challenge for a specific type, when the subject is already authorized by another
55
        // authorize type, f.e. when switching from http-01 to dns-01
56
57
        return null;
58
    }
59
}