LazyRpcClient::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
3
namespace ScayTrase\Api\Rpc\Decorators;
4
5
use ScayTrase\Api\Rpc\RpcClientInterface;
6
7
final class LazyRpcClient implements RpcClientInterface
8
{
9
    /** @var  LazyResponseCollection */
10
    private $collection;
11
    /** @var  RpcClientInterface */
12
    private $decoratedClient;
13
14
    /**
15
     * LazyRpcClient constructor.
16
     *
17
     * @param RpcClientInterface $decoratedClient
18
     */
19 8
    public function __construct(RpcClientInterface $decoratedClient)
20
    {
21 8
        $this->decoratedClient = $decoratedClient;
22 8
        $this->collection      = new LazyResponseCollection($decoratedClient);
23 8
    }
24
25 8
    public function invoke($calls)
26
    {
27
        // Reset collection if previous was already sent
28 8
        if ($this->collection->isFrozen()) {
29 2
            $this->collection = new LazyResponseCollection($this->decoratedClient);
30 2
        }
31
32 8
        if (!is_array($calls)) {
33 8
            $calls = [$calls];
34 8
        }
35
36 8
        foreach ($calls as $call) {
37 8
            $this->collection->append($call);
38 8
        }
39
40 8
        return $this->collection;
41
    }
42
}
43