UnauthorizedException::getHeaders()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
ccs 0
cts 0
cp 0
rs 10
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
/**
4
 * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
5
 * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
6
 *
7
 * Licensed under The MIT License
8
 * For full copyright and license information, please see the LICENSE.txt
9
 * Redistributions of files must retain the above copyright notice.
10
 *
11
 * @copyright     Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
12
 * @link          https://cakephp.org CakePHP(tm) Project
13
 * @since         1.0.0
14
 * @license       https://opensource.org/licenses/mit-license.php MIT License
15
 */
16
17
declare(strict_types=1);
18
19
namespace Phauthentic\Authentication\Authenticator\Exception;
20
21
use Phauthentic\Authentication\AuthenticationException;
22
use Throwable;
23
24
/**
25
 * An exception that holds onto the headers/body for an unauthorized response.
26
 */
27
class UnauthorizedException extends AuthenticationException
28
{
29
    /**
30
     * @var array<string, string>
31
     */
32
    protected array $headers = [];
33
34
    /**
35
     * @var string
36
     */
37
    protected string $body = '';
38
39
    /**
40
     * Constructor
41
     *
42
     * @param array<string, string> $headers The headers that should be sent in the unauthorized challenge response.
43
     * @param string $body The response body that should be sent in the challenge response.
44 24
     * @param int $code The exception code that will be used as a HTTP status code
45
     * @param \Throwable|null $previous Previous exception
46 24
     */
47 24
    public function __construct(array $headers, string $body = '', $code = 401, Throwable $previous = null)
48 24
    {
49 24
        parent::__construct('Authentication is required to continue', $code, $previous);
50
        $this->headers = $headers;
51
        $this->body = $body;
52
    }
53
54
    /**
55
     * Get the headers.
56 20
     *
57
     * @return array<string, string>
58 20
     */
59
    public function getHeaders(): array
60
    {
61
        return $this->headers;
62
    }
63
64
    /**
65
     * Get the body.
66 4
     *
67
     * @return string
68 4
     */
69
    public function getBody(): string
70
    {
71
        return $this->body;
72
    }
73
}
74