Completed
Pull Request — master (#7)
by Pavel
02:43
created

ExtraLazyResponseProxy::getBody()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace ScayTrase\Api\Rpc\Decorators;
4
5
use ScayTrase\Api\Rpc\RpcRequestInterface;
6
use ScayTrase\Api\Rpc\RpcResponseInterface;
7
8
final class ExtraLazyResponseProxy implements RpcResponseInterface
9
{
10
    /**
11
     * @var RpcRequestInterface
12
     */
13
    private $request;
14
    /**
15
     * @var LazyResponseCollection
16
     */
17
    private $collection;
18
19
    /** @var bool */
20
    private $initialized = false;
21
    /** @var RpcResponseInterface */
22
    private $response;
23
24
    /**
25
     * ExtraLazyResponseProxy constructor.
26
     *
27
     * @param RpcRequestInterface    $request
28
     * @param LazyResponseCollection $collection
29
     */
30 1
    public function __construct(RpcRequestInterface $request, LazyResponseCollection $collection)
31
    {
32 1
        $this->request    = $request;
33 1
        $this->collection = $collection;
34 1
    }
35
36
    /** {@inheritdoc} */
37 1
    public function isSuccessful()
38
    {
39 1
        return $this->getInternalResponse()->isSuccessful();
40
    }
41
42
    /** {@inheritdoc} */
43 1
    public function getError()
44
    {
45 1
        return $this->getInternalResponse()->getError();
46
    }
47
48
    /** {@inheritdoc} */
49 1
    public function getBody()
50
    {
51 1
        return $this->getInternalResponse()->getBody();
52
    }
53
54 1
    private function getInternalResponse()
55
    {
56 1
        if (!$this->initialized) {
57 1
            $this->response    = $this->collection->getResponse($this->request);
58 1
            $this->initialized = true;
59 1
        }
60
61 1
        return $this->response;
62
    }
63
}
64