Passed
Pull Request — master (#224)
by
unknown
13:06
created

Callback   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 6
dl 0
loc 17
rs 10
c 2
b 0
f 0
ccs 0
cts 0
cp 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A process() 0 3 1
A __construct() 0 4 1
1
<?php
2
3
namespace Yiisoft\Yii\Web\Middleware;
4
5
use Psr\Container\ContainerInterface;
6
use Psr\Http\Message\ResponseInterface;
7
use Psr\Http\Message\ServerRequestInterface;
8
use Psr\Http\Server\MiddlewareInterface;
9
use Psr\Http\Server\RequestHandlerInterface;
10
use Yiisoft\Injector\Injector;
11
12
final class Callback implements MiddlewareInterface
13
{
14
    /**
15
     * @var callable a PHP callback matching signature of [[MiddlewareInterface::process()]].
16
     */
17
    private $callback;
18
    private ContainerInterface $container;
19
20
    public function __construct(callable $callback, ContainerInterface $container)
21
    {
22
        $this->callback = $callback;
23
        $this->container = $container;
24
    }
25
26
    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
27
    {
28
        return (new Injector($this->container))->invoke($this->callback, [$request, $handler]);
29
    }
30
}
31