Passed
Pull Request — master (#18)
by Alexander
01:13
created

HttpBearer   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A withRealm() 0 5 1
A challenge() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Auth\Method;
6
7
use Psr\Http\Message\ResponseInterface;
8
9
/**
10
 * HttpBearer supports the authentication method based on HTTP Bearer token.
11
 */
12
final class HttpBearer extends HttpHeader
13
{
14
    protected string $headerName = 'Authorization';
15
    protected string $pattern = '/^Bearer\s+(.*?)$/';
16
    /**
17
     * @var string The HTTP authentication realm.
18
     */
19
    private string $realm = 'api';
20
21 3
    public function challenge(ResponseInterface $response): ResponseInterface
22
    {
23 3
        return $response->withHeader('WWW-Authenticate', "{$this->headerName} realm=\"{$this->realm}\"");
24
    }
25
26 1
    public function withRealm(string $realm): self
27
    {
28 1
        $new = clone $this;
29 1
        $new->realm = $realm;
30 1
        return $new;
31
    }
32
}
33