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

ProfiledResponseCollection::getResponse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 4
nc 1
nop 1
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
8
final class ProfiledResponseCollection implements \IteratorAggregate, ResponseCollectionInterface
9
{
10
    /** @var  ResponseCollectionInterface */
11
    private $collection;
12
    /** @var  ProfiledClientStorage */
13
    private $profiler;
14
15
    /**
16
     * ProfiledResponseCollection constructor.
17
     *
18
     * @param ResponseCollectionInterface $collection
19
     * @param ProfiledClientStorage                 $profiler
20
     */
21 2
    public function __construct(ResponseCollectionInterface $collection, ProfiledClientStorage $profiler)
22
    {
23 2
        $this->collection = $collection;
24 2
        $this->profiler   = $profiler;
25 2
    }
26
27
28
    /** {@inheritdoc} */
29 1
    public function getResponse(RpcRequestInterface $request)
30
    {
31 1
        $response = $this->collection->getResponse($request);
32 1
        $this->profiler->registerResponse($response, $request);
33
34 1
        return $response;
35
    }
36
37
    /** {@inheritdoc} */
38 1
    public function getIterator()
39
    {
40 1
        foreach ($this->collection as $response) {
41 1
            $this->profiler->registerResponse($response);
42 1
            yield $response;
43 1
        }
44 1
    }
45
}
46