Completed
Push — master ( f86d9b...1814a7 )
by Pavel
02:54
created

TraceableResponseCollection::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

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 9
ccs 5
cts 5
cp 1
rs 9.6666
cc 1
eloc 7
nc 1
nop 3
crap 1
1
<?php
2
3
namespace ScayTrase\Api\Rpc\Decorators;
4
5
use ScayTrase\Api\Rpc\ResponseCollectionInterface;
6
use ScayTrase\Api\Rpc\RpcRequestInterface;
7
use Symfony\Component\Stopwatch\Stopwatch;
8
9
final class TraceableResponseCollection implements \IteratorAggregate, ResponseCollectionInterface
10
{
11
    /** @var  ResponseCollectionInterface */
12
    private $collection;
13
    /** @var  Stopwatch */
14
    private $stopwatch;
15
    /** @var  string */
16
    private $client;
17
18
    /**
19
     * TraceableResponseCollection constructor.
20
     *
21
     * @param ResponseCollectionInterface $collection
22
     * @param Stopwatch                   $stopwatch
23
     * @param string                      $client
24
     */
25 2
    public function __construct(
26
        ResponseCollectionInterface $collection,
27
        Stopwatch $stopwatch,
28
        $client
29
    ) {
30 2
        $this->collection = $collection;
31 2
        $this->stopwatch  = $stopwatch;
32 2
        $this->client     = $client;
33 2
    }
34
35
    /** {@inheritdoc} */
36 1
    public function getResponse(RpcRequestInterface $request)
37
    {
38 1
        $this->stopwatch->start($this->client, TraceableClient::CATEGORY_RESPONSE);
39 1
        $response = $this->collection->getResponse($request);
40 1
        $this->stopwatch->stop($this->client);
41
42 1
        return $response;
43
    }
44
45
    /** {@inheritdoc} */
46 1
    public function getIterator()
47
    {
48 1
        $iterator = new TraceableCurrentIterator($this->collection, $this->stopwatch, $this->client);
49 1
        foreach ($iterator as $response) {
50 1
            yield $response;
51 1
        }
52 1
    }
53
}
54