TraceableClient   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

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

2 Methods

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