GetCertificate::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 4
dl 0
loc 8
ccs 0
cts 5
cp 0
rs 10
c 2
b 0
f 0
cc 2
nc 2
nop 3
crap 6
1
<?php
2
3
namespace LE_ACME2\Request\Order;
4
5
use LE_ACME2\Order;
6
use LE_ACME2\Request\AbstractRequest;
7
use LE_ACME2\Response;
8
9
use LE_ACME2\Connector;
10
use LE_ACME2\Cache;
11
use LE_ACME2\Exception;
12
use LE_ACME2\Utilities;
13
14
class GetCertificate extends AbstractRequest {
15
16
    protected $_order;
17
    protected $_orderResponse;
18
19
    private $_alternativeUrl = null;
20
21
    public function __construct(Order $order, Response\Order\AbstractOrder $orderResponse,
22
                                string $alternativeUrl = null
23
    ) {
24
        $this->_order = $order;
25
        $this->_orderResponse = $orderResponse;
26
27
        if($alternativeUrl !== null) {
28
            $this->_alternativeUrl = $alternativeUrl;
29
        }
30
    }
31
32
    /**
33
     * @throws Exception\InvalidResponse
34
     * @throws Exception\RateLimitReached
35
     * @throws Exception\ServiceUnavailable
36
     */
37
    public function getResponse() : Response\Order\GetCertificate {
38
39
        $url = $this->_alternativeUrl === null ?
40
            $this->_orderResponse->getCertificate() :
41
            $this->_alternativeUrl;
42
43
        $kid = Utilities\RequestSigner::KID(
44
            null,
45
            Cache\AccountResponse::getInstance()->get($this->_order->getAccount())->getLocation(),
0 ignored issues
show
Bug introduced by
It seems like get() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

45
            Cache\AccountResponse::getInstance()->/** @scrutinizer ignore-call */ get($this->_order->getAccount())->getLocation(),
Loading history...
46
            $url,
47
            Cache\NewNonceResponse::getInstance()->get()->getNonce(),
48
            $this->_order->getAccount()->getKeyDirectoryPath()
49
        );
50
51
        $result = Connector\Connector::getInstance()->request(
0 ignored issues
show
Bug introduced by
It seems like request() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

51
        $result = Connector\Connector::getInstance()->/** @scrutinizer ignore-call */ request(
Loading history...
52
            Connector\Connector::METHOD_POST,
53
            $url,
54
            $kid
55
        );
56
57
        return new Response\Order\GetCertificate($result);
58
    }
59
}