1 | <?php |
||
10 | abstract class AbstractRequest implements RequestInterface |
||
11 | { |
||
12 | /** |
||
13 | * @var int |
||
14 | */ |
||
15 | private $activity = Activity::WEB_REQUEST; |
||
16 | |||
17 | /** |
||
18 | * @var \DateTime |
||
19 | */ |
||
20 | private $date = null; |
||
21 | |||
22 | /** |
||
23 | * @var bool |
||
24 | */ |
||
25 | private $showCountry = false; |
||
26 | |||
27 | /** |
||
28 | * @var bool |
||
29 | */ |
||
30 | private $showSha1 = false; |
||
31 | |||
32 | /** |
||
33 | * @var string|null |
||
34 | */ |
||
35 | private $subscriberRef = null; |
||
36 | |||
37 | /** |
||
38 | * @param null|string $subscriberRef |
||
39 | */ |
||
40 | public function __construct($subscriberRef = null) |
||
44 | |||
45 | /** |
||
46 | * @param int $activity |
||
47 | * |
||
48 | * @return $this |
||
49 | */ |
||
50 | final public function setActivity($activity) |
||
56 | |||
57 | /** |
||
58 | * @param \DateTime|null $date |
||
59 | * |
||
60 | * @return $this |
||
61 | */ |
||
62 | final public function setDate(\DateTime $date = null) |
||
68 | |||
69 | /** |
||
70 | * @param bool $showCountry |
||
71 | * |
||
72 | * @return $this |
||
73 | */ |
||
74 | final public function setShowCountry($showCountry) |
||
80 | |||
81 | /** |
||
82 | * @param bool $showSha1 |
||
83 | * |
||
84 | * @return $this |
||
85 | */ |
||
86 | final public function setShowSha1($showSha1) |
||
92 | |||
93 | /** |
||
94 | * @return null|string |
||
95 | */ |
||
96 | final protected function getSubscriberRef() |
||
100 | |||
101 | /** |
||
102 | * {@inheritdoc} |
||
103 | */ |
||
104 | public function getParameters() |
||
132 | } |
||
133 |
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: