1 | <?php |
||
12 | class Seal implements QueryInterface |
||
13 | { |
||
14 | use FileFieldsTrait; |
||
15 | |||
16 | /** @var string document type */ |
||
17 | private $type; |
||
18 | |||
19 | /** @var boolean add document timestamp */ |
||
20 | private $timestamp; |
||
21 | |||
22 | /** @var array document to be signed */ |
||
23 | private $document; |
||
24 | |||
25 | /** |
||
26 | * @param string $type string document type |
||
27 | * @param array $document document to be signed |
||
28 | * @param boolean $timestamp boolean add document timestamp |
||
29 | */ |
||
30 | 7 | public function __construct( |
|
39 | |||
40 | /** |
||
41 | * Get fields |
||
42 | * @return array |
||
43 | */ |
||
44 | 3 | public function getFields() |
|
63 | |||
64 | /** |
||
65 | * Validation constraints for request data validation |
||
66 | * @return Assert\Collection |
||
67 | */ |
||
68 | 1 | public function getValidationConstraints() |
|
85 | |||
86 | /** |
||
87 | * Result object for this query result |
||
88 | * @return SealResult |
||
89 | */ |
||
90 | 1 | public function createResult() |
|
94 | |||
95 | /** |
||
96 | * API action name, part of full url |
||
97 | * @return string |
||
98 | */ |
||
99 | 1 | public function getAction() |
|
103 | |||
104 | /** |
||
105 | * HTTP method to use |
||
106 | * @return string |
||
107 | */ |
||
108 | 1 | public function getMethod() |
|
112 | } |
||
113 |
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.