1 | <?php declare(strict_types=1); |
||
16 | class Service extends OperatorResource implements Creatable, Listable, Retrievable, Updateable, Deletable |
||
17 | { |
||
18 | /** @var string */ |
||
19 | public $id; |
||
20 | |||
21 | /** @var string */ |
||
22 | public $name; |
||
23 | |||
24 | /** @var string */ |
||
25 | public $type; |
||
26 | |||
27 | /** @var string */ |
||
28 | public $description; |
||
29 | |||
30 | /** @var []Endpoint */ |
||
31 | public $endpoints; |
||
32 | |||
33 | /** @var array */ |
||
34 | public $links; |
||
35 | |||
36 | protected $resourceKey = 'service'; |
||
37 | protected $resourcesKey = 'services'; |
||
38 | |||
39 | /** |
||
40 | * @inheritdoc |
||
41 | */ |
||
42 | protected function getAliases() |
||
48 | |||
49 | /** |
||
50 | * {@inheritDoc} |
||
51 | * |
||
52 | 1 | * @param array $data {@see \OpenStack\Identity\v3\Api::postServices} |
|
53 | */ |
||
54 | 1 | public function create(array $data): Creatable |
|
59 | |||
60 | /** |
||
61 | 1 | * {@inheritDoc} |
|
62 | */ |
||
63 | 1 | public function retrieve() |
|
68 | |||
69 | /** |
||
70 | 1 | * {@inheritDoc} |
|
71 | */ |
||
72 | 1 | public function update() |
|
77 | 4 | ||
78 | /** |
||
79 | * {@inheritDoc} |
||
80 | 2 | */ |
|
81 | public function delete() |
||
85 | |||
86 | private function nameMatches(string $value): bool |
||
90 | |||
91 | private function typeMatches(string $value): bool |
||
95 | 4 | ||
96 | /** |
||
97 | 4 | * Retrieve the base URL for a service. |
|
98 | 2 | * |
|
99 | * @param string $name The name of the service as it appears in the catalog. |
||
100 | * @param string $type The type of the service as it appears in the catalog. |
||
101 | 2 | * @param string $region The region of the service as it appears in the catalog. |
|
102 | 2 | * @param string $interface The interface of the service as it appears in the catalog. |
|
103 | 2 | * |
|
104 | * @return string|false |
||
105 | 1 | */ |
|
106 | public function getUrl(string $name, string $type, string $region, string $interface) |
||
120 | } |
||
121 |
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.