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

TraceableResponseCollection::getIterator()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

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