1 | <?php |
||
25 | final class BlackMagicColumnReflectionPropertyMock extends ReflectionProperty |
||
26 | { |
||
27 | /** @var EntityManagerInterface */ |
||
28 | private $entityManager; |
||
29 | |||
30 | /** @var ClassMetadata */ |
||
31 | private $classMetadata; |
||
32 | |||
33 | /** @var ReflectionClass */ |
||
34 | private $classMetadataReflection; |
||
35 | |||
36 | /** @var Column */ |
||
37 | private $column; |
||
38 | |||
39 | /** @var string */ |
||
40 | private $fieldName; |
||
41 | |||
42 | /** @var BlackMagicDataLoader $dataLoader */ |
||
43 | private $dataLoader; |
||
44 | |||
45 | 1 | public function __construct( |
|
59 | |||
60 | public function getDeclaringClass(): ReflectionClass |
||
64 | |||
65 | public function getName(): string |
||
69 | |||
70 | public function getValue($object = null) |
||
78 | |||
79 | public function setValue($valueOrObject, $value = null): void |
||
98 | |||
99 | public function getDefaultValue() |
||
103 | |||
104 | public function getDocComment() |
||
108 | |||
109 | public function getModifiers(): int |
||
113 | |||
114 | public function getType(): ?ReflectionType |
||
118 | |||
119 | public function hasDefaultValue(): bool |
||
123 | |||
124 | public function hasType(): bool |
||
128 | |||
129 | public function isDefault(): bool |
||
133 | |||
134 | public function isInitialized($object = null): bool |
||
138 | |||
139 | public function isPrivate(): bool |
||
143 | |||
144 | public function isProtected(): bool |
||
148 | |||
149 | public function isPublic(): bool |
||
153 | |||
154 | public function isStatic(): bool |
||
158 | |||
159 | public function setAccessible($accessible): void |
||
162 | |||
163 | public function __toString(): string |
||
167 | } |
||
168 |
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.