Test Failed
Push — master ( a24517...57a539 )
by Fabian
02:46
created

AbstractOrder::getError()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 10
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0
cc 3
nc 2
nop 0
crap 12
1
<?php
2
3
namespace LE_ACME2\Response\Order;
4
5
use LE_ACME2\Response\AbstractResponse;
6
use LE_ACME2\Exception;
7
use LE_ACME2\Response\Order\Struct\OrderError;
8
9
abstract class AbstractOrder extends AbstractResponse {
10
11
    const STATUS_PENDING = 'pending';
12
    const STATUS_VALID = 'valid';
13
    const STATUS_READY = 'ready';
14
    const STATUS_INVALID = 'invalid';
15
16
    public function getLocation() : string {
17
18
        $matches = $this->_preg_match_headerLine($this->_pattern_header_location);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $matches is correct as $this->_preg_match_heade...attern_header_location) targeting LE_ACME2\Response\Abstra...preg_match_headerLine() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
19
        return trim($matches[1]);
20
    }
21
22
    public function getStatus() : string {
23
        return $this->_raw->body['status'];
24
    }
25
26
    public function getExpires() : string {
27
        return $this->_raw->body['expires'];
28
    }
29
30
    public function getIdentifiers() : array {
31
        return $this->_raw->body['identifiers'];
32
    }
33
34
    /**
35
     * @return array<string> Authorization urls
36
     */
37
    public function getAuthorizations() : array {
38
        return $this->_raw->body['authorizations'];
39
    }
40
41
    public function getFinalize() : string {
42
        return $this->_raw->body['finalize'];
43
    }
44
45
    public function getCertificate() : string {
46
        return $this->_raw->body['certificate'];
47
    }
48
49
    /**
50
     * @throws Exception\OrderStatusInvalid
51
     */
52
    protected function _isValid(): bool {
53
54
        if(!parent::_isValid()) {
55
            return false;
56
        }
57
58
        if(
59
            $this->getStatus() == AbstractOrder::STATUS_INVALID
60
        ) {
61
            throw new Exception\OrderStatusInvalid(
62
                '. Probably all authorizations have failed. ' . PHP_EOL .
63
                'Please see: ' . $this->getLocation() . PHP_EOL .
64
                'Continue by using $order->clear() after getting rid of the problem',
65
                $this,
66
            );
67
        }
68
69
        return true;
70
    }
71
72
    public function getError() : ?Struct\OrderError {
73
74
        if(
75
            !isset($this->_raw->body['error'])
76
            || !is_array($this->_raw->body['error'])
77
        ) {
78
            return null;
79
        }
80
81
        return OrderError::createFrom($this->_raw->body['error']);
82
    }
83
}