1 | <?php declare(strict_types=1); |
||
14 | class Token extends OperatorResource implements Creatable, Retrievable, \OpenStack\Common\Auth\Token |
||
15 | { |
||
16 | /** @var array */ |
||
17 | public $methods; |
||
18 | |||
19 | /** @var []Role */ |
||
20 | public $roles; |
||
21 | |||
22 | /** @var \DateTimeImmutable */ |
||
23 | public $expires; |
||
24 | |||
25 | /** @var Project */ |
||
26 | public $project; |
||
27 | |||
28 | /** @var Catalog */ |
||
29 | public $catalog; |
||
30 | |||
31 | /** @var mixed */ |
||
32 | public $extras; |
||
33 | |||
34 | /** @var User */ |
||
35 | public $user; |
||
36 | |||
37 | /** @var \DateTimeImmutable */ |
||
38 | public $issued; |
||
39 | |||
40 | /** @var string */ |
||
41 | public $id; |
||
42 | |||
43 | protected $resourceKey = 'token'; |
||
44 | protected $resourcesKey = 'tokens'; |
||
45 | |||
46 | protected $aliases = []; |
||
47 | |||
48 | /** |
||
49 | * @inheritdoc |
||
50 | */ |
||
51 | protected function getAliases() |
||
62 | |||
63 | /** |
||
64 | * {@inheritDoc} |
||
65 | 1 | */ |
|
66 | public function populateFromResponse(ResponseInterface $response) |
||
72 | |||
73 | 1 | /** |
|
74 | * @return string |
||
75 | 1 | */ |
|
76 | public function getId(): string |
||
80 | |||
81 | 1 | /** |
|
82 | * @return bool TRUE if the token has expired (and is invalid); FALSE otherwise. |
||
83 | 1 | */ |
|
84 | public function hasExpired(): bool |
||
88 | |||
89 | /** |
||
90 | * {@inheritDoc} |
||
91 | */ |
||
92 | public function retrieve() |
||
97 | 4 | ||
98 | 1 | /** |
|
99 | * {@inheritDoc} |
||
100 | * |
||
101 | 1 | * @param array $data {@see \OpenStack\Identity\v3\Api::postTokens} |
|
102 | 1 | */ |
|
103 | public function create(array $data): Creatable |
||
123 | } |
||
124 |
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.
Let’s take a look at an example:
Our function
my_function
expects aPost
object, and outputs the author of the post. The base classPost
returns a simple string and outputting a simple string will work just fine. However, the child classBlogPost
which is a sub-type ofPost
instead decided to return anobject
, and is therefore violating the SOLID principles. If aBlogPost
were passed tomy_function
, PHP would not complain, but ultimately fail when executing thestrtoupper
call in its body.