We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
1 | <?php |
||
9 | class Connection implements ConnectionInterface |
||
10 | { |
||
11 | /** @var Edge[] */ |
||
12 | protected $edges = []; |
||
13 | |||
14 | /** @var PageInfo */ |
||
15 | protected $pageInfo = null; |
||
16 | |||
17 | /** @var int */ |
||
18 | protected $totalCount = 0; |
||
19 | |||
20 | 56 | public function __construct($edges = [], PageInfo $pageInfo = null) |
|
25 | |||
26 | /** |
||
27 | * {@inheritdoc} |
||
28 | */ |
||
29 | 55 | public function getEdges() |
|
33 | |||
34 | /** |
||
35 | * {@inheritdoc} |
||
36 | */ |
||
37 | 1 | public function setEdges(iterable $edges): void |
|
41 | |||
42 | /** |
||
43 | * {@inheritdoc} |
||
44 | */ |
||
45 | 41 | public function getPageInfo(): ? PageInfo |
|
49 | |||
50 | /** |
||
51 | * {@inheritdoc} |
||
52 | */ |
||
53 | public function setPageInfo(PageInfo $pageInfo): void |
||
57 | |||
58 | /** |
||
59 | * {@inheritdoc} |
||
60 | */ |
||
61 | 29 | public function getTotalCount(): int |
|
65 | |||
66 | /** |
||
67 | * {@inheritdoc} |
||
68 | */ |
||
69 | 4 | public function setTotalCount(int $totalCount): void |
|
73 | } |
||
74 |
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.