Completed
Pull Request — master (#4)
by Pavel
10:02
created

ProfiledResponseCollection   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getResponse() 0 7 1
A getIterator() 0 7 2
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