Passed
Push — develop ( dfc3dd...7c6d84 )
by nguereza
01:37
created

AuthorizationCode::createNewAuthorizationCode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 5
dl 0
loc 12
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Platine OAuth2
5
 *
6
 * Platine OAuth2 is a library that implements the OAuth2 specification
7
 *
8
 * This content is released under the MIT License (MIT)
9
 *
10
 * Copyright (c) 2020 Platine OAuth2
11
 *
12
 * Permission is hereby granted, free of charge, to any person obtaining a copy
13
 * of this software and associated documentation files (the "Software"), to deal
14
 * in the Software without restriction, including without limitation the rights
15
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16
 * copies of the Software, and to permit persons to whom the Software is
17
 * furnished to do so, subject to the following conditions:
18
 *
19
 * The above copyright notice and this permission notice shall be included in all
20
 * copies or substantial portions of the Software.
21
 *
22
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28
 * SOFTWARE.
29
 */
30
31
declare(strict_types=1);
32
33
namespace Platine\OAuth2\Entity;
34
35
/**
36
 * @class AuthorizationCode
37
 * @package Platine\OAuth2\Entity
38
 */
39
class AuthorizationCode extends BaseToken
40
{
41
    /**
42
     * The redirect URI
43
     * @var string
44
     */
45
    protected string $redirectUri;
46
47
    /**
48
     * Create new authorization code
49
     * @param int $ttl
50
     * @param string|null $redirectUri
51
     * @param TokenOwnerInterface|null $owner
52
     * @param Client|null $client
53
     * @param array<string>|Scope[]|null $scopes
54
     * @return $this
55
     */
56
    public static function createNewAuthorizationCode(
57
        int $ttl,
58
        ?string $redirectUri = null,
59
        ?TokenOwnerInterface $owner = null,
60
        ?Client $client = null,
61
        ?array $scopes = null
62
    ): self {
63
        $code = static::createNew($ttl, $owner, $client, $scopes);
64
65
        $code->redirectUri = $redirectUri ?? '';
66
67
        return $code;
68
    }
69
70
    /**
71
     * {@inheritdoc}
72
     */
73
    public static function hydrate(array $data): self
74
    {
75
        $code = parent::hydrate($data);
76
        $code->redirectUri = $data['redirect_uri'];
77
78
        return $code;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $code returns the type Platine\OAuth2\Entity\BaseToken which includes types incompatible with the type-hinted return Platine\OAuth2\Entity\AuthorizationCode.
Loading history...
79
    }
80
81
    /**
82
     * Return the redirect URI
83
     * @return string
84
     */
85
    public function getRedirectUri(): string
86
    {
87
        return $this->redirectUri;
88
    }
89
}
90