Passed
Push — master ( a6d59a...971523 )
by butschster
16:28 queued 13s
created

AuthTransportMiddleware::process()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 2
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Spiral\Auth\Middleware;
6
7
use Psr\EventDispatcher\EventDispatcherInterface;
8
use Psr\Http\Message\ResponseInterface;
9
use Psr\Http\Message\ServerRequestInterface;
10
use Psr\Http\Server\MiddlewareInterface;
11
use Psr\Http\Server\RequestHandlerInterface;
12
use Spiral\Auth\ActorProviderInterface;
13
use Spiral\Auth\TokenStorageInterface;
14
use Spiral\Auth\TransportRegistry;
15
use Spiral\Core\ScopeInterface;
16
17
/**
18
 * Auth by specific transport.
19
 */
20
final class AuthTransportMiddleware implements MiddlewareInterface
21
{
22
    private readonly AuthMiddleware $authMiddleware;
23
24 2
    public function __construct(
25
        string $transportName,
26
        ScopeInterface $scope,
27
        ActorProviderInterface $actorProvider,
28
        TokenStorageInterface $tokenStorage,
29
        TransportRegistry $transportRegistry,
30
        ?EventDispatcherInterface $eventDispatcher = null
31
    ) {
32 2
        $this->authMiddleware = new AuthMiddleware(
0 ignored issues
show
Bug introduced by
The property authMiddleware is declared read-only in Spiral\Auth\Middleware\AuthTransportMiddleware.
Loading history...
33
            $scope,
34
            $actorProvider,
35
            $tokenStorage,
36 2
            $this->getTransportRegistry($transportRegistry, $transportName),
37
            $eventDispatcher
38
        );
39
    }
40
41
    /**
42
     * @throws \Throwable
43
     */
44 1
    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
45
    {
46 1
        return $this->authMiddleware->process($request, $handler);
47
    }
48
49 2
    private function getTransportRegistry(TransportRegistry $registry, string $transportName): TransportRegistry
50
    {
51 2
        $transports = new TransportRegistry();
52 2
        $transports->setTransport($transportName, $registry->getTransport($transportName));
53
54 2
        return $transports;
55
    }
56
}
57