Passed
Pull Request — master (#5)
by Pavel
05:52
created

PsrResponder   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
dl 0
loc 33
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A createResponse() 0 3 1
1
<?php
2
3
namespace Lamoda\Metric\Responder;
4
5
use Lamoda\Metric\Collector\MetricCollectorInterface;
6
use Psr\Http\Message\ResponseInterface;
7
8
final class PsrResponder
9
{
10
    /**
11
     * @var MetricCollectorInterface
12
     */
13
    private $collector;
14
    /**
15
     * @var ResponseFactoryInterface
16
     */
17
    private $factory;
18
    /**
19
     * @var array
20
     */
21
    private $options;
22
23 1
    public function __construct(
24
        MetricCollectorInterface $collector,
25
        ResponseFactoryInterface $factory,
26
        array $options = []
27
    ) {
28 1
        $this->collector = $collector;
29 1
        $this->factory = $factory;
30 1
        $this->options = $options;
31 1
    }
32
33
    /**
34
     * Create PSR-7 HTTP response for collected metrics
35
     *
36
     * @return ResponseInterface
37
     */
38 1
    public function createResponse(): ResponseInterface
39
    {
40 1
        return $this->factory->create($this->collector->collect(), $this->options);
41
    }
42
}
43