RevokeCertificate::getResponse()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 26
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
dl 0
loc 26
ccs 0
cts 13
cp 0
rs 9.7
c 1
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace LE_ACME2\Request\Order;
4
5
use LE_ACME2\Response;
6
use LE_ACME2\Request\AbstractRequest;
7
8
use LE_ACME2\Connector;
9
use LE_ACME2\Cache;
10
use LE_ACME2\Exception;
11
use LE_ACME2\Struct;
12
use LE_ACME2\Utilities;
13
14
class RevokeCertificate extends AbstractRequest {
15
16
    protected $_certificateBundle;
17
    protected $_reason;
18
19
    public function __construct(Struct\CertificateBundle $certificateBundle, $reason) {
20
21
        $this->_certificateBundle = $certificateBundle;
22
        $this->_reason = $reason;
23
    }
24
25
    /**
26
     * @throws Exception\InvalidResponse
27
     * @throws Exception\RateLimitReached
28
     * @throws Exception\ServiceUnavailable
29
     */
30
    public function getResponse() : Response\Order\RevokeCertificate {
31
32
        $certificate = file_get_contents($this->_certificateBundle->path . $this->_certificateBundle->certificate);
33
        preg_match('~-----BEGIN\sCERTIFICATE-----(.*)-----END\sCERTIFICATE-----~s', $certificate, $matches);
34
        $certificate = trim(Utilities\Base64::UrlSafeEncode(base64_decode(trim($matches[1]))));
35
36
        $payload = [
37
            'certificate' => $certificate,
38
            'reason' => $this->_reason
39
        ];
40
41
        $jwk = Utilities\RequestSigner::JWKString(
42
            $payload,
43
            Cache\DirectoryResponse::getInstance()->get()->getRevokeCert(),
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

43
            Cache\DirectoryResponse::getInstance()->/** @scrutinizer ignore-call */ get()->getRevokeCert(),
Loading history...
44
            Cache\NewNonceResponse::getInstance()->get()->getNonce(),
45
            $this->_certificateBundle->path,
46
            $this->_certificateBundle->private
47
        );
48
49
        $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

49
        $result = Connector\Connector::getInstance()->/** @scrutinizer ignore-call */ request(
Loading history...
50
            Connector\Connector::METHOD_POST,
51
            Cache\DirectoryResponse::getInstance()->get()->getRevokeCert(),
52
            $jwk
53
        );
54
55
        return new Response\Order\RevokeCertificate($result);
56
    }
57
}