Completed
Push — master ( f61680...98184f )
by Pavel
02:28
created

LazyRpcClient::__construct()   A

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 4
    public function __construct(RpcClientInterface $decoratedClient)
20
    {
21 4
        $this->decoratedClient = $decoratedClient;
22 4
        $this->collection      = new LazyResponseCollection($decoratedClient);
23 4
    }
24
25 4
    public function invoke($calls)
26
    {
27
        // Reset collection if previous was already sent
28 4
        if ($this->collection->isFrozen()) {
29 1
            $this->collection = new LazyResponseCollection($this->decoratedClient);
30 1
        }
31
32 4
        if (!is_array($calls)) {
33 4
            $calls = [$calls];
34 4
        }
35
36 4
        foreach ($calls as $call) {
37 4
            $this->collection->append($call);
38 4
        }
39
40 4
        return $this->collection;
41
    }
42
}
43