AuthorizationCodeResponse   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

6 Methods

Rating   Name   Duplication   Size   Complexity  
A error() 0 3 1
A code() 0 3 1
A __construct() 0 3 1
A errorDescription() 0 3 1
A isError() 0 3 1
A state() 0 3 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