Completed
Pull Request — master (#4)
by Pavel
10:02
created

TraceableClient   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 3
dl 0
loc 37
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A invoke() 0 12 1
1
<?php
2
3
namespace Bankiru\Api\Client;
4
5
use ScayTrase\Api\Rpc\RpcClientInterface;
6
use Symfony\Component\Stopwatch\Stopwatch;
7
8
class TraceableClient implements RpcClientInterface
9
{
10
    /** @var  RpcClientInterface */
11
    private $client;
12
    /** @var  Stopwatch */
13
    private $stopwatch;
14
    /** @var  string */
15
    private $clientName;
16
17
    /**
18
     * TraceableClient constructor.
19
     *
20
     * @param RpcClientInterface $client
21
     * @param Stopwatch          $stopwatch
22
     * @param string             $clientName
23
     */
24 3
    public function __construct(RpcClientInterface $client, Stopwatch $stopwatch, $clientName = 'api_client')
25
    {
26 3
        $this->client     = $client;
27 3
        $this->stopwatch  = $stopwatch;
28 3
        $this->clientName = (string)$clientName;
29 3
    }
30
31
    /** {@inheritdoc} */
32 1
    public function invoke($calls)
33 1
    {
34 1
        $this->stopwatch->start($this->clientName, 'rpc_call');
35 1
        $collection = new TraceableResponseCollection(
36 1
            $this->client->invoke($calls),
37 1
            $this->stopwatch,
38 1
            $this->clientName
39 1
        );
40 1
        $this->stopwatch->stop($this->clientName);
41
42 1
        return $collection;
43
    }
44
}
45