1 | <?php |
||
23 | class CompositionCollection extends ArrayCollection implements Tabbable |
||
24 | { |
||
25 | /** |
||
26 | * Tabulation Identity. |
||
27 | * @var int |
||
28 | */ |
||
29 | protected $tabulation; |
||
30 | |||
31 | /** |
||
32 | * @var CompositionMethodCollection |
||
33 | */ |
||
34 | protected $methods; |
||
35 | |||
36 | /** |
||
37 | * Initializes a new ArrayCollection. |
||
38 | * |
||
39 | * @param array $elements |
||
40 | */ |
||
41 | 42 | public function __construct(array $elements = array()) |
|
47 | |||
48 | /** |
||
49 | * {@inheritdoc} |
||
50 | */ |
||
51 | 6 | public function getTabulation() |
|
55 | |||
56 | /** |
||
57 | * {@inheritdoc} |
||
58 | */ |
||
59 | 6 | public function getTabulationFormatted() |
|
63 | |||
64 | /** |
||
65 | * @inheritdoc |
||
66 | */ |
||
67 | 42 | public function setTabulation($tabulation) |
|
73 | |||
74 | /** |
||
75 | * Adds a new Composition at CompositionCollection. |
||
76 | * |
||
77 | * @param string $composition |
||
78 | * |
||
79 | * @return bool |
||
80 | */ |
||
81 | 8 | public function add($composition) |
|
88 | |||
89 | /** |
||
90 | * @param CompositionMethodInterface $method |
||
91 | * @return bool |
||
92 | */ |
||
93 | 5 | public function addMethod(CompositionMethodInterface $method) |
|
98 | |||
99 | /** |
||
100 | * @return CompositionMethodCollection |
||
101 | */ |
||
102 | 7 | public function getMethods() |
|
106 | |||
107 | /** |
||
108 | * @param CompositionMethodCollection $methods |
||
109 | * @return CompositionCollection |
||
110 | */ |
||
111 | 1 | public function setMethods(CompositionMethodCollection $methods) |
|
116 | |||
117 | /** |
||
118 | * @param string $composition |
||
119 | * @return bool |
||
120 | */ |
||
121 | 6 | public function addComposition($composition) |
|
125 | |||
126 | /** |
||
127 | * Parse the Composition Collection to string. |
||
128 | * @return string |
||
129 | */ |
||
130 | 13 | public function toString() |
|
146 | } |
||
147 |
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.