1 | <?php |
||
49 | class PropertyList implements PropertyListInterface |
||
50 | { |
||
51 | /** |
||
52 | * Property values |
||
53 | * |
||
54 | * @var array[] |
||
55 | */ |
||
56 | protected $values = []; |
||
57 | /** |
||
58 | * Property names |
||
59 | * |
||
60 | * @var \stdClass[] |
||
61 | */ |
||
62 | protected $names = []; |
||
63 | /** |
||
64 | * Name cursor mapping |
||
65 | * |
||
66 | * @var int[] |
||
67 | */ |
||
68 | protected $nameToCursor = []; |
||
69 | /** |
||
70 | * Internal cursor |
||
71 | * |
||
72 | * @var int |
||
73 | */ |
||
74 | protected $cursor = 0; |
||
75 | |||
76 | /** |
||
77 | * Unset a property |
||
78 | * |
||
79 | * @param \stdClass|string $iri IRI |
||
80 | * |
||
81 | * @throws ErrorException |
||
82 | */ |
||
83 | 1 | public function offsetUnset($iri) |
|
91 | |||
92 | /** |
||
93 | * Return the number of properties |
||
94 | * |
||
95 | * @return int Number of properties |
||
96 | */ |
||
97 | 2 | public function count() |
|
101 | |||
102 | /** |
||
103 | * Return the current property values |
||
104 | * |
||
105 | * @return array Property values |
||
106 | */ |
||
107 | 8 | public function current() |
|
111 | |||
112 | /** |
||
113 | * Move forward to next element |
||
114 | */ |
||
115 | 8 | public function next() |
|
119 | |||
120 | /** |
||
121 | * Return the current IRI key |
||
122 | * |
||
123 | * @return \stdClass IRI key |
||
124 | */ |
||
125 | 8 | public function key() |
|
129 | |||
130 | /** |
||
131 | * Checks if current position is valid |
||
132 | * |
||
133 | * @return boolean The current position is valid |
||
134 | */ |
||
135 | 17 | public function valid() |
|
139 | |||
140 | /** |
||
141 | * Rewind the Iterator to the first element |
||
142 | */ |
||
143 | 17 | public function rewind() |
|
147 | |||
148 | /** |
||
149 | * Add a property |
||
150 | * |
||
151 | * @param \stdClass|Iri $property Property |
||
152 | */ |
||
153 | 38 | public function add($property) |
|
168 | |||
169 | /** |
||
170 | * Return whether a property exists |
||
171 | * |
||
172 | * @param \stdClass|Iri|string $iri IRI |
||
173 | * |
||
174 | * @return boolean Property exists |
||
175 | */ |
||
176 | 38 | public function offsetExists($iri) |
|
188 | |||
189 | /** |
||
190 | * Get a particular property cursor by its profiled name |
||
191 | * |
||
192 | * @param Iri $iri IRI |
||
193 | * |
||
194 | * @return int Property cursor |
||
195 | * @throws OutOfBoundsException If the property name is unknown |
||
196 | */ |
||
197 | 32 | protected function getProfiledPropertyCursor($iri) |
|
208 | |||
209 | /** |
||
210 | * Handle an unknown property name |
||
211 | * |
||
212 | * @param string $name Property name |
||
213 | * |
||
214 | * @throws OutOfBoundsException If the property name is unknown |
||
215 | */ |
||
216 | 41 | protected function handleUnknownName($name) |
|
223 | |||
224 | /** |
||
225 | * Get a particular property cursor by its name |
||
226 | * |
||
227 | * @param string $name Property name |
||
228 | * |
||
229 | * @return int Property cursor |
||
230 | */ |
||
231 | 10 | protected function getPropertyCursor($name) |
|
242 | |||
243 | /** |
||
244 | * Set a particular property |
||
245 | * |
||
246 | * @param \stdClass|Iri|string $iri IRI |
||
247 | * @param array $value Property values |
||
248 | */ |
||
249 | 9 | public function offsetSet($iri, $value) |
|
258 | |||
259 | /** |
||
260 | * Get a particular property |
||
261 | * |
||
262 | * @param \stdClass|Iri|string $iri IRI |
||
263 | * |
||
264 | * @return array Property values |
||
265 | * @throws OutOfBoundsException If the property name is unknown |
||
266 | */ |
||
267 | 16 | public function &offsetGet($iri) |
|
275 | } |
||
276 |
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.