1 | <?php |
||
8 | class Request implements RequestInterface |
||
9 | { |
||
10 | private $id; |
||
11 | private $customerId; |
||
12 | private $facilityId; |
||
13 | private $login; |
||
14 | private $password; |
||
15 | private $method; |
||
16 | private $url; |
||
17 | private $template; |
||
18 | |||
19 | public function __construct($method, $url) |
||
24 | |||
25 | public function fetch(array $data) |
||
47 | |||
48 | private function getBody(array $data) |
||
66 | |||
67 | public function setTemplate($template) |
||
71 | |||
72 | public function getId() |
||
76 | |||
77 | public function setId($id) |
||
81 | |||
82 | public function getCustomerId() |
||
86 | |||
87 | public function setCustomerId($customerId) |
||
91 | |||
92 | public function getFacilityId() |
||
96 | |||
97 | public function setFacilityId($facilityId) |
||
101 | |||
102 | public function getLogin() |
||
106 | |||
107 | public function setLogin($login) |
||
111 | |||
112 | public function getPassword() |
||
116 | |||
117 | public function setPassword($password) |
||
121 | |||
122 | public function getUrl() |
||
126 | } |
||
127 |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the parent class: