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

HttpBearer::setRealm()   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
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
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