Passed
Push — master ( 044b78...4447be )
by Fabian
02:11
created

Get   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Test Coverage

Coverage 8%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 9
eloc 22
dl 0
loc 55
ccs 2
cts 25
cp 0.08
rs 10
c 4
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getIdentifier() 0 5 1
A getExpires() 0 2 1
A getChallenge() 0 29 5
A getChallenges() 0 2 1
A getStatus() 0 2 1
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
    /**
30
     * @param string $type
31
     * @return Struct\Challenge|null
32
     */
33
    public function getChallenge(string $type) : ?Struct\Challenge {
34
35
        foreach($this->getChallenges() as $challenge) {
36
37
            if($type == $challenge['type']) {
38
39
                $error = null;
40
                if(isset($challenge[ 'error' ]) && $challenge[ 'error' ] != "") {
41
                    $error = new Struct\ChallengeError(
42
                        $challenge[ 'error' ][ 'type' ],
43
                        $challenge[ 'error' ][ 'detail' ],
44
                        $challenge[ 'error' ][ 'status' ],
45
                    );
46
                }
47
48
                return new Struct\Challenge(
49
                    $challenge[ 'type' ],
50
                    $challenge[ 'status' ],
51
                    $challenge[ 'url' ],
52
                    $challenge[ 'token' ],
53
                    $error,
54
                );
55
            }
56
        }
57
58
        // There is not a challenge for a specific type, when the subject is already authorized by another
59
        // authorize type, f.e. when switching from http-01 to dns-01
60
61
        return null;
62
    }
63
}