Passed
Push — master ( 95786b...34331f )
by Paweł
05:27 queued 02:18
created

KernelClient   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 81.82%

Importance

Changes 4
Bugs 1 Features 0
Metric Value
eloc 11
c 4
b 1
f 0
dl 0
loc 32
ccs 9
cts 11
cp 0.8182
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getResponse() 0 3 1
A __construct() 0 4 1
A request() 0 6 1
1
<?php
2
/**
3
 * Copyright (c) 2020.
4
 * @author Paweł Antosiak <[email protected]>
5
 */
6
7
declare(strict_types=1);
8
9
namespace Gorynych\Http;
10
11
use Symfony\Component\HttpFoundation\Response;
12
13
final class KernelClient
14
{
15
    private Kernel $kernel;
16
    private RequestFactoryInterface $requestFactory;
17
    private ?Response $response;
18
19 1
    public function __construct(Kernel $kernel, RequestFactoryInterface $requestFactory)
20
    {
21 1
        $this->kernel = $kernel;
22 1
        $this->requestFactory = $requestFactory;
23 1
    }
24
25
    /**
26
     * Performs request on the kernel
27
     *
28
     * @param string $method
29
     * @param string $uri
30
     * @param string[][] $options
31
     * @return Response
32
     */
33 1
    public function request(string $method, string $uri, array $options = []): Response
34
    {
35 1
        return $this->response = $this->kernel
36 1
            ->reboot()
37 1
            ->handleRequest(
38 1
                $this->requestFactory->create($method, $uri, $options)
39
            );
40
    }
41
42
    public function getResponse(): ?Response
43
    {
44
        return $this->response;
45
    }
46
}
47