1 | <?php namespace Anomaly\Streams\Platform\Search; |
||
11 | class SearchCriteria |
||
12 | { |
||
13 | use Hookable; |
||
14 | |||
15 | /** |
||
16 | * The search builder. |
||
17 | * |
||
18 | * @var Builder |
||
19 | */ |
||
20 | protected $query; |
||
21 | |||
22 | /** |
||
23 | * The model object. |
||
24 | * |
||
25 | * @var EloquentModel |
||
26 | */ |
||
27 | protected $model; |
||
28 | |||
29 | /** |
||
30 | * Create a new SearchCriteria instance. |
||
31 | * |
||
32 | * @param Builder $query |
||
33 | * @param EloquentModel $model |
||
34 | */ |
||
35 | public function __construct(Builder $query, EloquentModel $model) |
||
40 | |||
41 | /** |
||
42 | * Get the paginated entries. |
||
43 | * |
||
44 | * @return Collection |
||
45 | */ |
||
46 | public function paginate($perPage = 15, $pageName = 'page', $page = null) |
||
58 | |||
59 | /** |
||
60 | * Get the entries. |
||
61 | * |
||
62 | * @return Collection |
||
63 | */ |
||
64 | public function get() |
||
68 | |||
69 | /** |
||
70 | * Get the first entry. |
||
71 | * |
||
72 | * @return Presenter |
||
73 | */ |
||
74 | public function first() |
||
78 | |||
79 | /** |
||
80 | * Route through __call. |
||
81 | * |
||
82 | * @param $name |
||
83 | * @return Builder|null |
||
84 | */ |
||
85 | public function __get($name) |
||
89 | |||
90 | /** |
||
91 | * Call the method on the query. |
||
92 | * |
||
93 | * @param $name |
||
94 | * @param $arguments |
||
95 | * @return Builder|null |
||
96 | */ |
||
97 | public function __call($name, $arguments) |
||
107 | |||
108 | /** |
||
109 | * Return the string. |
||
110 | * |
||
111 | * @return string |
||
112 | */ |
||
113 | public function __toString() |
||
117 | } |
||
118 |
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.