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

Finalize   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 22
dl 0
loc 45
ccs 0
cts 20
cp 0
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getResponse() 0 28 2
A __construct() 0 4 1
1
<?php
2
3
namespace LE_ACME2\Request\Order;
4
5
use LE_ACME2\Request\AbstractRequest;
6
use LE_ACME2\Response;
7
8
use LE_ACME2\Connector;
9
use LE_ACME2\Cache;
10
use LE_ACME2\Exception;
11
use LE_ACME2\Utilities;
12
13
use LE_ACME2\Order;
14
15
class Finalize extends AbstractRequest {
16
17
    protected $_order;
18
    protected $_orderResponse;
19
20
    public function __construct(Order $order, Response\Order\AbstractOrder $orderResponse) {
21
22
        $this->_order = $order;
23
        $this->_orderResponse = $orderResponse;
24
    }
25
26
    /**
27
     * @return Response\AbstractResponse|Response\Order\Finalize
28
     * @throws Exception\InvalidResponse
29
     * @throws Exception\RateLimitReached
30
     * @throws Exception\OpenSSLException
31
     */
32
    public function getResponse() : Response\AbstractResponse {
33
34
        $csr = Utilities\Certificate::generateCSR($this->_order);
35
36
        if(preg_match('~-----BEGIN\sCERTIFICATE\sREQUEST-----(.*)-----END\sCERTIFICATE\sREQUEST-----~s', $csr, $matches))
37
            $csr = $matches[1];
38
39
        $csr = trim(Utilities\Base64::UrlSafeEncode(base64_decode($csr)));
40
41
        $payload = [
42
            'csr' => $csr
43
        ];
44
45
        $kid = Utilities\RequestSigner::KID(
46
            $payload,
47
            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

47
            Cache\AccountResponse::getInstance()->/** @scrutinizer ignore-call */ get($this->_order->getAccount())->getLocation(),
Loading history...
48
            $this->_orderResponse->getFinalize(),
49
            Cache\NewNonceResponse::getInstance()->get()->getNonce(),
50
            $this->_order->getAccount()->getKeyDirectoryPath()
51
        );
52
53
        $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

53
        $result = Connector\Connector::getInstance()->/** @scrutinizer ignore-call */ request(
Loading history...
54
            Connector\Connector::METHOD_POST,
55
            $this->_orderResponse->getFinalize(),
56
            $kid
57
        );
58
59
        return new Response\Order\Finalize($result);
60
    }
61
}