Completed
Push — master ( f86d9b...1814a7 )
by Pavel
02:54
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
c 0
b 0
f 0
dl 0
loc 6
ccs 5
cts 5
cp 1
rs 9.4285
cc 1
eloc 4
nc 1
nop 3
crap 1
1
<?php
2
3
namespace ScayTrase\Api\Rpc\Decorators;
4
5
use ScayTrase\Api\Rpc\RpcClientInterface;
6
use Symfony\Component\Stopwatch\Stopwatch;
7
8
final class TraceableClient implements RpcClientInterface
9
{
10
    const CATEGORY_REQUEST  = 'rpc_call';
11
    const CATEGORY_RESPONSE = 'rpc_response';
12
13
    /** @var  RpcClientInterface */
14
    private $client;
15
    /** @var  Stopwatch */
16
    private $stopwatch;
17
    /** @var  string */
18
    private $clientName;
19
20
    /**
21
     * TraceableClient constructor.
22
     *
23
     * @param RpcClientInterface $client
24
     * @param Stopwatch          $stopwatch
25
     * @param string             $clientName
26
     */
27 2
    public function __construct(RpcClientInterface $client, Stopwatch $stopwatch, $clientName = 'api_client')
28
    {
29 2
        $this->client     = $client;
30 2
        $this->stopwatch  = $stopwatch;
31 2
        $this->clientName = (string)$clientName;
32 2
    }
33
34
    /** {@inheritdoc} */
35 2
    public function invoke($calls)
36
    {
37 2
        $this->stopwatch->start($this->clientName, self::CATEGORY_REQUEST);
38 2
        $collection = new TraceableResponseCollection(
39 2
            $this->client->invoke($calls),
40 2
            $this->stopwatch,
41 2
            $this->clientName
42 2
        );
43 2
        $this->stopwatch->stop($this->clientName);
44
45 2
        return $collection;
46
    }
47
}
48