LazyRpcClient   A
last analyzed

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 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