Completed
Pull Request — master (#4)
by Pavel
10:02
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
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Bankiru\Api\Client;
4
5
use Bankiru\Api\DataCollector\RpcProfiler;
6
use ScayTrase\Api\Rpc\ResponseCollectionInterface;
7
use ScayTrase\Api\Rpc\RpcRequestInterface;
8
9
class ProfiledResponseCollection implements \IteratorAggregate, ResponseCollectionInterface
10
{
11
    /** @var  ResponseCollectionInterface */
12
    private $collection;
13
    /** @var  RpcProfiler */
14
    private $profiler;
15
16
    /**
17
     * ProfiledResponseCollection constructor.
18
     *
19
     * @param ResponseCollectionInterface $collection
20
     * @param RpcProfiler                 $profiler
21
     */
22 1
    public function __construct(ResponseCollectionInterface $collection, RpcProfiler $profiler)
23
    {
24 1
        $this->collection = $collection;
25 1
        $this->profiler   = $profiler;
26 1
    }
27
28
29
    /** {@inheritdoc} */
30 1
    public function getResponse(RpcRequestInterface $request)
31
    {
32 1
        $response = $this->collection->getResponse($request);
33 1
        $this->profiler->registerResponse($response, $request);
34
35 1
        return $response;
36
    }
37
38
    /** {@inheritdoc} */
39 1
    public function getIterator()
40
    {
41 1
        foreach ($this->collection as $response) {
42 1
            $this->profiler->registerResponse($response);
43 1
            yield $response;
44 1
        }
45 1
    }
46
}
47