Passed
Push — master ( 767d18...65c593 )
by Ekin
11:48
created

Factory::buildFromResponse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 2
dl 0
loc 8
ccs 5
cts 5
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace ekinhbayar\GitAmp\Response;
4
5
use Amp\Promise;
6
use ekinhbayar\GitAmp\Event\Factory as EventFactory;
7
use Amp\Http\Client\Response;
8
use Psr\Log\LoggerInterface;
9
use function Amp\call;
10
11
class Factory
12
{
13
    private EventFactory $eventFactory;
14
15
    private LoggerInterface $logger;
16
17 3
    public function __construct(EventFactory $eventFactory, LoggerInterface $logger)
18
    {
19 3
        $this->eventFactory = $eventFactory;
20 3
        $this->logger       = $logger;
21 3
    }
22
23 3
    public function build(): Results
24
    {
25 3
        return new Results($this->eventFactory, $this->logger);
26
    }
27
28 2
    public function buildFromResponse(string $eventNamespace, Response $response): Promise
29
    {
30 2
        return call(function() use ($eventNamespace, $response) {
31 2
            $results = $this->build();
32
33 2
            yield $results->appendResponse($eventNamespace, $response);
34
35 2
            return $results;
36 2
        });
37
    }
38
}
39