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

NewNonceResponse   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 12
dl 0
loc 30
ccs 0
cts 12
cp 0
rs 10
c 1
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 12 2
A set() 0 2 1
A __construct() 0 1 1
1
<?php
2
namespace LE_ACME2\Cache;
3
4
use LE_ACME2\SingletonTrait;
5
6
use LE_ACME2\Exception;
7
use LE_ACME2\Request;
8
use LE_ACME2\Response;
9
10
class NewNonceResponse {
11
12
    use SingletonTrait;
13
14
    private function __construct() {}
15
16
    private $_responses = [];
17
    private $_index = 0;
18
19
    /**
20
     * @return Response\GetNewNonce
21
     * @throws Exception\InvalidResponse
22
     * @throws Exception\RateLimitReached
23
     */
24
    public function get() : Response\GetNewNonce {
25
26
        if(array_key_exists($this->_index, $this->_responses)) {
27
            return $this->_responses[$this->_index];
28
        }
29
        $this->_responses[$this->_index] = null;
30
31
        $request = new Request\GetNewNonce();
32
        $response = $request->getResponse();
33
        $this->set($response);
34
35
        return $response;
36
    }
37
38
    public function set(Response\GetNewNonce $response) : void {
39
        $this->_responses[$this->_index] = $response;
40
    }
41
}