1 | <?php |
||
13 | class SWLCustomTexts { |
||
14 | |||
15 | /** |
||
16 | * Group for this CustomTexts |
||
17 | * |
||
18 | * @since 0.2 |
||
19 | * |
||
20 | * @var SWLGroup |
||
21 | */ |
||
22 | private $group; |
||
23 | |||
24 | /** |
||
25 | * Array holding custom texts to be sent in mails |
||
26 | * |
||
27 | * @since 0.2 |
||
28 | * |
||
29 | * @var array or null |
||
30 | */ |
||
31 | private $customTexts = null; |
||
32 | |||
33 | public function __construct( SWLGroup $group ) { |
||
36 | |||
37 | /** |
||
38 | * Sets an array of CustomTexts by reading from the db |
||
39 | * for this group. |
||
40 | * |
||
41 | * @since 0.2 |
||
42 | */ |
||
43 | private function initCustomTexts() { |
||
65 | |||
66 | /** |
||
67 | * Returns an array of CustomTexts set by the admin in WatchlistConditions |
||
68 | * for this group and property. |
||
69 | * |
||
70 | * @since 0.2 |
||
71 | * |
||
72 | * @param SMWDIProperty $property |
||
73 | * @param String $newValue |
||
74 | * |
||
75 | * @return String or false |
||
76 | */ |
||
77 | public function getPropertyCustomText( SMWDIProperty $property, $newValue ) { |
||
85 | } |
||
86 |
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.