|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace OpenStack\Identity\v2\Models; |
|
4
|
|
|
|
|
5
|
|
|
use OpenStack\Common\Resource\Alias; |
|
6
|
|
|
use OpenStack\Common\Transport\Utils; |
|
7
|
|
|
use Psr\Http\Message\ResponseInterface; |
|
8
|
|
|
use OpenStack\Common\Resource\OperatorResource; |
|
9
|
|
|
use OpenStack\Common\Resource\ValueResource; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Represents an Identity v2 Token. |
|
13
|
|
|
* |
|
14
|
|
|
* @package OpenStack\Identity\v2\Models |
|
15
|
|
|
*/ |
|
16
|
|
|
class Token extends OperatorResource implements \OpenStack\Common\Auth\Token |
|
17
|
|
|
{ |
|
18
|
|
|
/** @var \DateTimeImmutable */ |
|
19
|
|
|
public $issuedAt; |
|
20
|
|
|
|
|
21
|
|
|
/** @var string */ |
|
22
|
|
|
public $id; |
|
23
|
|
|
|
|
24
|
|
|
/** @var \DateTimeImmutable */ |
|
25
|
|
|
public $expires; |
|
26
|
|
|
|
|
27
|
|
|
/** @var Tenant */ |
|
28
|
|
|
public $tenant; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @inheritdoc |
|
32
|
|
|
*/ |
|
33
|
|
View Code Duplication |
protected static function getAlias(): Alias |
|
|
|
|
|
|
34
|
2 |
|
{ |
|
35
|
|
|
$alias = parent::getAlias(); |
|
36
|
2 |
|
|
|
37
|
|
|
if (!$alias->hasAliases(self::class)) { |
|
38
|
2 |
|
$alias |
|
39
|
|
|
->add(self::class, 'tenant', 'tenant', Tenant::class) |
|
40
|
|
|
->add(self::class, 'expires', 'expires', \DateTimeImmutable::class) |
|
41
|
1 |
|
->add(self::class, 'issued_at', 'issuedAt', \DateTimeImmutable::class); |
|
42
|
|
|
} |
|
43
|
1 |
|
|
|
44
|
|
|
return $alias; |
|
45
|
|
|
} |
|
46
|
2 |
|
|
|
47
|
|
|
/** |
|
48
|
2 |
|
* {@inheritDoc} |
|
49
|
|
|
*/ |
|
50
|
|
|
public function populateFromResponse(ResponseInterface $response): self |
|
51
|
|
|
{ |
|
52
|
|
|
$this->populateFromArray(Utils::jsonDecode($response)['access']['token']); |
|
53
|
|
|
|
|
54
|
|
|
return $this; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function getId(): string |
|
58
|
|
|
{ |
|
59
|
|
|
return $this->id; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function hasExpired(): bool |
|
63
|
|
|
{ |
|
64
|
|
|
return $this->expires <= new \DateTimeImmutable('now', $this->expires->getTimezone()); |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.