AuthorizationCodeResponse::errorDescription()   A
last analyzed

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
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Parroauth2\Client\EndPoint\Authorization;
4
5
/**
6
 * Wrap the authorization response for a response_type=code
7
 *
8
 * @see https://tools.ietf.org/html/rfc6749#section-4.1.2
9
 *
10
 * @psalm-immutable
11
 */
12
class AuthorizationCodeResponse
13
{
14
    /**
15
     * @var array<string, mixed>
16
     */
17
    private $parameters;
18
19
    /**
20
     * AuthorizationCodeResponse constructor.
21
     *
22
     * @param array<string, mixed> $parameters
23
     */
24 10
    public function __construct(array $parameters)
25
    {
26 10
        $this->parameters = $parameters;
27 10
    }
28
29
    /**
30
     * Get the authorization code
31
     *
32
     * @return string
33
     */
34 4
    public function code(): string
35
    {
36 4
        return $this->parameters['code'];
37
    }
38
39
    /**
40
     * Get the state
41
     *
42
     * @return string
43
     */
44 10
    public function state(): string
45
    {
46 10
        return $this->parameters['state'] ?? '';
47
    }
48
49
    /**
50
     * Check if the response is an error response
51
     *
52
     * @return bool
53
     */
54 6
    public function isError(): bool
55
    {
56 6
        return isset($this->parameters['error']);
57
    }
58
59
    /**
60
     * Get the error code
61
     *
62
     * @return string
63
     */
64 2
    public function error(): string
65
    {
66 2
        return $this->parameters['error'];
67
    }
68
69
    /**
70
     * Get the human readable error message
71
     *
72
     * @return string|null
73
     */
74 2
    public function errorDescription(): ?string
75
    {
76 2
        return $this->parameters['error_description'] ?? null;
77
    }
78
}
79