| 1 | <?php |
||
| 16 | class FantaPaginatorAdapter implements AdapterInterface |
||
| 17 | { |
||
| 18 | private $adapter; |
||
| 19 | |||
| 20 | 7 | public function __construct(PaginatorAdapterInterface $adapter) |
|
| 24 | |||
| 25 | /** |
||
| 26 | * Returns the number of results. |
||
| 27 | * |
||
| 28 | * @return int The number of results |
||
| 29 | */ |
||
| 30 | 1 | public function getNbResults() |
|
| 34 | |||
| 35 | /** |
||
| 36 | * Returns Aggregations. |
||
| 37 | * |
||
| 38 | * @return mixed |
||
| 39 | * |
||
| 40 | * @api |
||
| 41 | */ |
||
| 42 | 1 | public function getAggregations() |
|
| 46 | |||
| 47 | /** |
||
| 48 | * Returns Suggestions. |
||
| 49 | * |
||
| 50 | * @return mixed |
||
| 51 | * |
||
| 52 | * @api |
||
| 53 | */ |
||
| 54 | 1 | public function getSuggests() |
|
| 58 | |||
| 59 | /** |
||
| 60 | * Returns a slice of the results. |
||
| 61 | * |
||
| 62 | * @param int $offset The offset |
||
| 63 | * @param int $length The length |
||
| 64 | * |
||
| 65 | * @return array|\Traversable The slice |
||
| 66 | */ |
||
| 67 | 1 | public function getSlice($offset, $length) |
|
| 71 | |||
| 72 | /** |
||
| 73 | * {@inheritdoc} |
||
| 74 | */ |
||
| 75 | 1 | public function getMaxScore() |
|
| 79 | } |
||
| 80 |
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.