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

LazyRpcClient   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 36
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A invoke() 0 17 4
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