| 1 | <?php declare(strict_types=1); |
||
| 13 | class Entry extends OperatorResource |
||
| 14 | { |
||
| 15 | /** @var string */ |
||
| 16 | public $name; |
||
| 17 | |||
| 18 | /** @var string */ |
||
| 19 | public $type; |
||
| 20 | |||
| 21 | /** @var []Endpoint */ |
||
| 22 | public $endpoints = []; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @var array |
||
| 26 | */ |
||
| 27 | protected $aliases = []; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @inheritdoc |
||
| 31 | 1 | */ |
|
| 32 | protected function getAliases() |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Indicates whether this catalog entry matches a certain name and type. |
||
| 41 | * |
||
| 42 | * @param string $name |
||
| 43 | * @param string $type |
||
| 44 | 2 | * |
|
| 45 | * @return bool TRUE if it's a match, FALSE if not |
||
| 46 | 2 | */ |
|
| 47 | 1 | public function matches(string $name, string $type): bool |
|
| 51 | |||
| 52 | 1 | /** |
|
| 53 | * Retrieves the catalog entry's URL according to a specific region and URL type |
||
| 54 | * |
||
| 55 | * @param string $region |
||
| 56 | * @param string $urlType |
||
| 57 | * |
||
| 58 | * @return string |
||
| 59 | */ |
||
| 60 | public function getEndpointUrl(string $region, string $urlType): string |
||
| 70 | } |
||
| 71 |
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_functionexpects aPostobject, and outputs the author of the post. The base classPostreturns a simple string and outputting a simple string will work just fine. However, the child classBlogPostwhich is a sub-type ofPostinstead decided to return anobject, and is therefore violating the SOLID principles. If aBlogPostwere passed tomy_function, PHP would not complain, but ultimately fail when executing thestrtouppercall in its body.