Passed
Push — master ( 5679ef...aad9e9 )
by Kirill
04:11
created

OverwriteFirewall   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 6
c 1
b 0
f 0
dl 0
loc 24
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A denyAccess() 0 3 1
A __construct() 0 4 1
1
<?php
2
3
/**
4
 * Spiral Framework.
5
 *
6
 * @license   MIT
7
 * @author    Anton Titov (Wolfy-J)
8
 */
9
10
declare(strict_types=1);
11
12
namespace Spiral\Auth\Middleware\Firewall;
13
14
use Psr\Http\Message\ResponseInterface as Response;
15
use Psr\Http\Message\ServerRequestInterface as Request;
16
use Psr\Http\Message\UriInterface;
17
use Psr\Http\Server\RequestHandlerInterface;
18
19
/**
20
 * Changes the target URL to login form without altering URL in client browser. Changes response status.
21
 */
22
final class OverwriteFirewall extends AbstractFirewall
23
{
24
    /** @var UriInterface */
25
    private $uri;
26
27
    /** @var int */
28
    private $status;
29
30
    /**
31
     * @param UriInterface $uri
32
     * @param int          $status
33
     */
34
    public function __construct(UriInterface $uri, int $status = 401)
35
    {
36
        $this->uri = $uri;
37
        $this->status = $status;
38
    }
39
40
    /**
41
     * @inheritDoc
42
     */
43
    protected function denyAccess(Request $request, RequestHandlerInterface $handler): Response
44
    {
45
        return $handler->handle($request->withUri($this->uri))->withStatus($this->status);
46
    }
47
}
48