1 | <?php |
||
24 | class ResourceMetadata extends GenericMetadata implements ResourceMetadataInterface |
||
25 | { |
||
26 | /** |
||
27 | * @var string |
||
28 | * @internal |
||
29 | */ |
||
30 | public $name; |
||
31 | |||
32 | /** |
||
33 | * @var AttributeMetadataInterface[] |
||
34 | * @internal |
||
35 | */ |
||
36 | public $attributes = []; |
||
37 | |||
38 | /** |
||
39 | * @var RelationshipMetadataInterface[] |
||
40 | * @internal |
||
41 | */ |
||
42 | public $relationships = []; |
||
43 | |||
44 | /*** |
||
45 | * @var string|null |
||
46 | * @internal |
||
47 | */ |
||
48 | public $discField; |
||
49 | |||
50 | /** |
||
51 | * @var array |
||
52 | * @internal |
||
53 | */ |
||
54 | public $discMap; |
||
55 | |||
56 | /** |
||
57 | * Constructor |
||
58 | * |
||
59 | * @param string $name |
||
60 | * @param $className |
||
61 | */ |
||
62 | public function __construct($name, $className) |
||
68 | |||
69 | /** |
||
70 | * @inheritdoc |
||
71 | */ |
||
72 | public function getName() |
||
76 | |||
77 | /** |
||
78 | * @inheritdoc |
||
79 | */ |
||
80 | public function getAttributes() |
||
84 | |||
85 | /** |
||
86 | * Add resource attribute metadata |
||
87 | * |
||
88 | * @param AttributeMetadataInterface $attribute |
||
89 | * @return $this |
||
90 | */ |
||
91 | public function addAttribute(AttributeMetadataInterface $attribute) |
||
97 | |||
98 | /** |
||
99 | * @inheritdoc |
||
100 | */ |
||
101 | public function getRelationships() |
||
105 | |||
106 | /** |
||
107 | * Add resource relationship metadata |
||
108 | * |
||
109 | * @param RelationshipMetadataInterface $relationship |
||
110 | * @return $this |
||
111 | */ |
||
112 | public function addRelationship(RelationshipMetadataInterface $relationship) |
||
118 | |||
119 | /** |
||
120 | * @inheritdoc |
||
121 | */ |
||
122 | public function getDiscriminatorField() |
||
126 | |||
127 | /** |
||
128 | * Sets discriminator field |
||
129 | * |
||
130 | * @param string|null $field |
||
131 | * @return $this |
||
132 | */ |
||
133 | public function setDiscriminatorField($field = null) |
||
139 | |||
140 | /** |
||
141 | * Sets discriminator map |
||
142 | * |
||
143 | * @param array $map |
||
144 | * @return $this |
||
145 | */ |
||
146 | public function setDiscriminatorMap(array $map) |
||
152 | |||
153 | /** |
||
154 | * @inheritdoc |
||
155 | */ |
||
156 | public function getDiscriminatorClass($value) |
||
167 | |||
168 | /** |
||
169 | * Merge resource metadata |
||
170 | * |
||
171 | * @param mixed $metadata |
||
172 | * @return $this |
||
173 | */ |
||
174 | public function mergeMetadata($metadata) |
||
190 | } |
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.