1 | <?php |
||
20 | class Demo extends Model |
||
21 | { |
||
22 | |||
23 | /** |
||
24 | * Language model instance |
||
25 | * @var \gplcart\core\models\Language $language |
||
26 | */ |
||
27 | protected $language; |
||
28 | |||
29 | /** |
||
30 | * @param LanguageModel $language |
||
31 | */ |
||
32 | public function __construct(LanguageModel $language) |
||
38 | |||
39 | /** |
||
40 | * Returns an array of handlers |
||
41 | */ |
||
42 | public function getHandlers() |
||
64 | |||
65 | /** |
||
66 | * Returns a handler |
||
67 | * @param string $handler_id |
||
68 | * @return array |
||
69 | */ |
||
70 | public function getHandler($handler_id) |
||
75 | |||
76 | /** |
||
77 | * Create a demo content |
||
78 | * @param string $handler_id |
||
79 | * @param integer $store_id |
||
80 | * @return string|integer |
||
81 | */ |
||
82 | public function create($handler_id, $store_id) |
||
93 | |||
94 | /** |
||
95 | * Deletes the demo content |
||
96 | * @param string $handler_id |
||
97 | * @param integer $store_id |
||
98 | * @return string|integer |
||
99 | */ |
||
100 | public function delete($handler_id, $store_id) |
||
111 | |||
112 | /** |
||
113 | * Set an array of created entity IDs in the database |
||
114 | * @param string $handler_id |
||
115 | * @param integer $store_id |
||
116 | * @param array $data |
||
117 | * @return boolean |
||
118 | */ |
||
119 | public function setCreatedEntityId($handler_id, $store_id, array $data) |
||
125 | |||
126 | /** |
||
127 | * Returns an array of previously created entity IDs |
||
128 | * @param string $handler_id |
||
129 | * @param integer $store_id |
||
130 | * @return array |
||
131 | */ |
||
132 | public function getCreatedEntityId($handler_id, $store_id) |
||
136 | |||
137 | /** |
||
138 | * Removes all saved data about previously created entity IDs from the database |
||
139 | * @param string $handler_id |
||
140 | * @param integer $store_id |
||
141 | * @return boolean |
||
142 | */ |
||
143 | public function resetCreatedEntityId($handler_id, $store_id) |
||
147 | |||
148 | } |
||
149 |
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.