Passed
Branch master (fc5382)
by Fabian
03:13
created

InvalidResponse   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 9
eloc 21
dl 0
loc 47
ccs 0
cts 21
cp 0
rs 10
c 4
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getResponseStatusType() 0 2 1
A getResponseStatusDetail() 0 6 2
A getRawResponse() 0 2 1
A __construct() 0 18 4
A getResponseStatus() 0 2 1
1
<?php
2
3
namespace LE_ACME2\Exception;
4
5
use LE_ACME2\Connector\RawResponse;
6
7
class InvalidResponse extends AbstractException {
8
9
    const RESPONSE_STATUS_TYPE_ERROR_SERVER_INTERNAL = 'urn:ietf:params:acme:error:serverInternal';
10
    const RESPONSE_STATUS_TYPE_ERROR_MALFORMED = 'urn:ietf:params:acme:error:malformed';
11
12
    private $_rawResponse;
13
    private $_responseStatus;
14
    private $_responseStatusType;
15
16
    public function __construct(RawResponse $rawResponse, string $responseStatus = null) {
17
18
        $this->_rawResponse = $rawResponse;
19
        $this->_responseStatus = $responseStatus;
20
21
        if($responseStatus === '') {
22
            $responseStatus = 'Unknown response status';
23
        }
24
25
        if(isset($this->_rawResponse->body['type'])) {
26
            $responseStatus = $this->_responseStatusType = $this->_rawResponse->body['type'];
27
        }
28
29
        if(isset($this->_rawResponse->body['detail'])) {
30
            $responseStatus .= ' - ' . $this->_rawResponse->body['detail'];
31
        }
32
33
        parent::__construct('Invalid response received: ' . $responseStatus);
34
    }
35
36
    public function getRawResponse() : RawResponse {
37
        return $this->_rawResponse;
38
    }
39
40
    public function getResponseStatus() : ?string {
41
        return $this->_responseStatus;
42
    }
43
    
44
    public function getResponseStatusType() : ?string {
45
        return $this->_responseStatusType;
46
    }
47
48
    public function getResponseStatusDetail() : ?string {
49
50
        if(isset($this->_rawResponse->body['detail'])) {
51
            return $this->_rawResponse->body['detail'];
52
        }
53
        return null;
54
    }
55
}