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

TraceableClient::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 3
crap 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