Test Failed
Push — master ( a6c6b3...3c4c8a )
by Felipe
06:56 queued 04:26
created

MiddlewareHandlerFactory::__invoke()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * This file is part of coisa/http.
5
 *
6
 * (c) Felipe Sayão Lobato Abreu <[email protected]>
7
 *
8
 * This source file is subject to the license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
declare(strict_types=1);
13
14
namespace CoiSA\Http\Client;
15
16
use CoiSA\Http\Handler\MiddlewareHandler;
17
use Psr\Container\ContainerInterface;
18
use Psr\Http\Server\MiddlewareInterface;
19
use Psr\Http\Server\RequestHandlerInterface;
20
21
/**
22
 * Class HttpPlugHandlerFactory
23
 *
24
 * @package CoiSA\Http\Client
25
 */
26
final class MiddlewareHandlerFactory
27
{
28
    /**
29
     * @param ContainerInterface $container
30
     *
31
     * @return MiddlewareHandler
32
     */
33
    public function __invoke(ContainerInterface $container): MiddlewareHandler
34
    {
35
        return $this->plugMiddlewareAndHandler(
36
            $container->get(MiddlewareInterface::class),
37
            $container->get(RequestHandlerInterface::class)
38
        );
39
    }
40
41
    /**
42
     * @param MiddlewareInterface     $middleware
43
     * @param RequestHandlerInterface $requestHandler
44
     *
45
     * @return MiddlewareHandler
46
     */
47
    public function plugMiddlewareAndHandler(MiddlewareInterface $middleware, RequestHandlerInterface $requestHandler): MiddlewareHandler
48
    {
49
        return new MiddlewareHandler($middleware, $requestHandler);
50
    }
51
}
52