Passed
Push — master ( 22cd0c...a717b5 )
by Florian
02:38 queued 10s
created

UnauthorizedException   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
eloc 8
dl 0
loc 44
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getHeaders() 0 3 1
A getBody() 0 3 1
1
<?php
2
declare(strict_types=1);
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
namespace Phauthentic\Authentication\Authenticator\Exception;
17
18
use RuntimeException;
19
20
/**
21
 * An exception that holds onto the headers/body for an unauthorized response.
22
 */
23
class UnauthorizedException extends RuntimeException implements AuthenticationExceptionInterface
24
{
25
    /**
26
     * @var array
27
     */
28
    protected $headers = [];
29
30
    /**
31
     * @var string
32
     */
33
    protected $body = '';
34
35
    /**
36
     * Constructor
37
     *
38
     * @param array $headers The headers that should be sent in the unauthorized challenge response.
39
     * @param string $body The response body that should be sent in the challenge response.
40
     * @param int $code The exception code that will be used as a HTTP status code
41
     */
42 18
    public function __construct(array $headers, string $body = '', $code = 401)
43
    {
44 18
        parent::__construct('Authentication is required to continue', $code);
45 18
        $this->headers = $headers;
46 18
        $this->body = $body;
47 18
    }
48
49
    /**
50
     * Get the headers.
51
     *
52
     * @return array
53
     */
54 15
    public function getHeaders(): array
55
    {
56 15
        return $this->headers;
57
    }
58
59
    /**
60
     * Get the body.
61
     *
62
     * @return string
63
     */
64 3
    public function getBody(): string
65
    {
66 3
        return $this->body;
67
    }
68
}
69