RedirectUri   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 139
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 13
lcom 1
cbo 4
dl 0
loc 139
ccs 32
cts 32
cp 1
rs 10
c 0
b 0
f 0

10 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 2
A getIdentifier() 0 4 1
A setIdentifier() 0 6 1
A getClientIdentifier() 0 4 1
A setClientIdentifier() 0 6 1
A getValue() 0 4 1
A setValue() 0 17 3
A getUri() 0 4 1
A setCreatedAt() 0 7 1
A setUpdatedAt() 0 7 1
1
<?php declare(strict_types=1);
2
3
namespace Limoncello\Passport\Entities;
4
5
/**
6
 * Copyright 2015-2019 [email protected]
7
 *
8
 * Licensed under the Apache License, Version 2.0 (the "License");
9
 * you may not use this file except in compliance with the License.
10
 * You may obtain a copy of the License at
11
 *
12
 * http://www.apache.org/licenses/LICENSE-2.0
13
 *
14
 * Unless required by applicable law or agreed to in writing, software
15
 * distributed under the License is distributed on an "AS IS" BASIS,
16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
 * See the License for the specific language governing permissions and
18
 * limitations under the License.
19
 */
20
21
use DateTimeInterface;
22
use Limoncello\Passport\Contracts\Entities\RedirectUriInterface;
23
use Limoncello\Passport\Exceptions\InvalidArgumentException;
24
use Psr\Http\Message\UriInterface;
25
use Zend\Diactoros\Uri;
26
27
/**
28
 * @package Limoncello\Passport
29
 */
30
abstract class RedirectUri extends DatabaseItem implements RedirectUriInterface
31
{
32
    /** Field name */
33
    const FIELD_ID = 'id_redirect_uri';
34
35
    /** Field name */
36
    const FIELD_ID_CLIENT = Client::FIELD_ID;
37
38
    /** Field name */
39
    const FIELD_VALUE = 'value';
40
41
    /**
42
     * @var int|null
43
     */
44
    private $identifierField;
45
46
    /**
47
     * @var string|null
48
     */
49
    private $clientIdentifierField;
50
51
    /**
52
     * @var string|null
53
     */
54
    private $valueField;
55
56
    /**
57
     * @var Uri|null
58
     */
59
    private $uriObject;
60
61
    /**
62
     * Constructor.
63
     */
64 21
    public function __construct()
65
    {
66 21
        if ($this->hasDynamicProperty(static::FIELD_ID) === true) {
67
            $this
68 1
                ->setIdentifier((int)$this->{static::FIELD_ID})
69 1
                ->setClientIdentifier($this->{static::FIELD_ID_CLIENT})
70 1
                ->setValue($this->{static::FIELD_VALUE});
71
        }
72
    }
73
74
    /**
75
     * @inheritdoc
76
     */
77 2
    public function getIdentifier(): ?int
78
    {
79 2
        return $this->identifierField;
80
    }
81
82
    /**
83
     * @inheritdoc
84
     */
85 17
    public function setIdentifier(int $identifier): RedirectUriInterface
86
    {
87 17
        $this->identifierField = $identifier;
88
89 17
        return $this;
90
    }
91
92
    /**
93
     * @inheritdoc
94
     */
95 19
    public function getClientIdentifier(): ?string
96
    {
97 19
        return $this->clientIdentifierField;
98
    }
99
100
    /**
101
     * @inheritdoc
102
     */
103 18
    public function setClientIdentifier(string $identifier): RedirectUriInterface
104
    {
105 18
        $this->clientIdentifierField = $identifier;
106
107 18
        return $this;
108
    }
109
110
    /**
111
     * @inheritdoc
112
     */
113 19
    public function getValue(): ?string
114
    {
115 19
        return $this->valueField;
116
    }
117
118
    /**
119
     * @inheritdoc
120
     */
121 19
    public function setValue(string $uri): RedirectUriInterface
122
    {
123
        // @link https://tools.ietf.org/html/rfc6749#section-3.1.2
124
        //
125
        // The redirection endpoint URI MUST be an absolute URI.
126
        // The endpoint URI MUST NOT include a fragment component.
127
128 19
        $uriObject = new Uri($uri);
129 19
        if (empty($uriObject->getHost()) === true || empty($uriObject->getFragment()) === false) {
130 1
            throw new InvalidArgumentException('redirect URI');
131
        }
132
133 19
        $this->valueField = $uri;
134 19
        $this->uriObject  = $uriObject;
135
136 19
        return $this;
137
    }
138
139
    /**
140
     * @inheritdoc
141
     */
142 1
    public function getUri(): UriInterface
143
    {
144 1
        return $this->uriObject;
145
    }
146
147
    /**
148
     * @inheritdoc
149
     */
150 17
    public function setCreatedAt(DateTimeInterface $createdAt): RedirectUriInterface
151
    {
152
        /** @var RedirectUriInterface $self */
153 17
        $self = $this->setCreatedAtImpl($createdAt);
154
155 17
        return $self;
156
    }
157
158
    /**
159
     * @inheritdoc
160
     */
161 1
    public function setUpdatedAt(DateTimeInterface $createdAt): RedirectUriInterface
162
    {
163
        /** @var RedirectUriInterface $self */
164 1
        $self = $this->setUpdatedAtImpl($createdAt);
165
166 1
        return $self;
167
    }
168
}
169