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 bool |
||
34 | */ |
||
35 | private $showCardType = false; |
||
36 | |||
37 | /** |
||
38 | * @var string|null |
||
39 | */ |
||
40 | private $subscriberRef = null; |
||
41 | |||
42 | /** |
||
43 | * @param null|string $subscriberRef |
||
44 | */ |
||
45 | public function __construct($subscriberRef = null) |
||
49 | |||
50 | /** |
||
51 | * @param int $activity |
||
52 | * |
||
53 | * @return $this |
||
54 | */ |
||
55 | final public function setActivity($activity) |
||
61 | |||
62 | /** |
||
63 | * @param \DateTime|null $date |
||
64 | * |
||
65 | * @return $this |
||
66 | */ |
||
67 | final public function setDate(\DateTime $date = null) |
||
73 | |||
74 | /** |
||
75 | * @param bool $showCountry |
||
76 | * |
||
77 | * @return $this |
||
78 | */ |
||
79 | final public function setShowCountry($showCountry) |
||
85 | |||
86 | /** |
||
87 | * @param bool $showSha1 |
||
88 | * |
||
89 | * @return $this |
||
90 | */ |
||
91 | final public function setShowSha1($showSha1) |
||
97 | |||
98 | /** |
||
99 | * @param bool $showCardType |
||
100 | * |
||
101 | * @return $this |
||
102 | */ |
||
103 | final public function setShowCardType($showCardType) |
||
109 | |||
110 | /** |
||
111 | * @return null|string |
||
112 | */ |
||
113 | final protected function getSubscriberRef() |
||
117 | |||
118 | /** |
||
119 | * {@inheritdoc} |
||
120 | */ |
||
121 | public function getParameters() |
||
155 | } |
||
156 |
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: