Passed
Push — master ( 73997f...b8272a )
by Felipe
02:04
created

Dispatcher   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 57
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 1
A handle() 0 3 1
A process() 0 3 1
A sendRequest() 0 3 1
1
<?php declare(strict_types=1);
2
/*
3
 * This file is part of coisa/http.
4
 *
5
 * (c) Felipe Sayão Lobato Abreu <[email protected]>
6
 *
7
 * This source file is subject to the license that is bundled
8
 * with this source code in the file LICENSE.
9
 */
10
11
namespace CoiSA\Http;
12
13
use CoiSA\Http\Client\RequestHandlerClient;
14
use CoiSA\Http\Handler\MiddlewareHandler;
15
use Psr\Http\Message\RequestInterface;
16
use Psr\Http\Message\ResponseInterface;
17
use Psr\Http\Message\ServerRequestFactoryInterface;
18
use Psr\Http\Message\ServerRequestInterface;
19
use Psr\Http\Server\MiddlewareInterface;
20
use Psr\Http\Server\RequestHandlerInterface;
21
22
/**
23
 * Class Dispatcher
24
 *
25
 * @package CoiSA\Http
26
 */
27
class Dispatcher implements DispatcherInterface
28
{
29
    /**
30
     * @var RequestHandlerInterface
31
     */
32
    private $handler;
33
34
    /**
35
     * @var PsrHttpClient
0 ignored issues
show
Bug introduced by
The type CoiSA\Http\PsrHttpClient was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
36
     */
37
    private $client;
38
39
    /**
40
     * Dispatcher constructor.
41
     *
42
     * @param RequestHandlerInterface $handler
43
     * @param MiddlewareInterface $middleware
44
     * @param ServerRequestFactoryInterface|null $serverRequestFactory
45
     */
46
    public function __construct(
47
        RequestHandlerInterface $handler,
48
        MiddlewareInterface $middleware,
49
        ServerRequestFactoryInterface $serverRequestFactory = null
50
    ) {
51
        $this->handler = new MiddlewareHandler(
52
            $middleware,
53
            $handler
54
        );
55
56
        $this->client  = new RequestHandlerClient(
0 ignored issues
show
Documentation Bug introduced by
It seems like new CoiSA\Http\Client\Re... $serverRequestFactory) of type CoiSA\Http\Client\RequestHandlerClient is incompatible with the declared type CoiSA\Http\PsrHttpClient of property $client.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
57
            $this->handler,
58
            $serverRequestFactory
59
        );
60
    }
61
62
    /**
63
     * {@inheritdoc}
64
     */
65
    public function sendRequest(RequestInterface $request): ResponseInterface
66
    {
67
        return $this->client->sendRequest($request);
68
    }
69
70
    /**
71
     * {@inheritdoc}
72
     */
73
    public function handle(ServerRequestInterface $request): ResponseInterface
74
    {
75
        return $this->handler->handle($request);
76
    }
77
78
    /**
79
     * {@inheritdoc}
80
     */
81
    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
82
    {
83
        return $this->handler->process($request, $handler);
0 ignored issues
show
Bug introduced by
The method process() does not exist on Psr\Http\Server\RequestHandlerInterface. It seems like you code against a sub-type of Psr\Http\Server\RequestHandlerInterface such as CoiSA\Http\Handler\MiddlewareHandler or CoiSA\Http\Middleware\RequestHandlerMiddleware or CoiSA\Http\DispatcherInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

83
        return $this->handler->/** @scrutinizer ignore-call */ process($request, $handler);
Loading history...
84
    }
85
}
86