AuthenticationFailureHandler   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 13
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A handle() 0 7 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Auth\Handler;
6
7
use Psr\Http\Message\ResponseFactoryInterface;
8
use Psr\Http\Message\ResponseInterface;
9
use Psr\Http\Message\ServerRequestInterface;
10
use Psr\Http\Server\RequestHandlerInterface;
11
use Yiisoft\Http\Status;
12
13
/**
14
 * Default authentication failure handler. Responds with "401 Unauthorized" HTTP status code.
15
 */
16
final class AuthenticationFailureHandler implements RequestHandlerInterface
17
{
18 7
    public function __construct(private ResponseFactoryInterface $responseFactory)
19
    {
20 7
    }
21
22 3
    public function handle(ServerRequestInterface $request): ResponseInterface
23
    {
24 3
        $response = $this->responseFactory->createResponse(Status::UNAUTHORIZED);
25 3
        $response
26 3
            ->getBody()
27 3
            ->write('Your request was made with invalid credentials.');
28 3
        return $response;
29
    }
30
}
31