1 | <?php |
||
20 | abstract class AbstractRequest implements RequestInterface |
||
21 | { |
||
22 | /** |
||
23 | * @var int |
||
24 | * |
||
25 | * @Enum(class="Nexy\PayboxDirect\Enum\Activity", showKeys=true) |
||
26 | */ |
||
27 | private $activity = null; |
||
28 | |||
29 | /** |
||
30 | * @var \DateTime |
||
31 | * |
||
32 | * @Assert\Type("\DateTime") |
||
33 | */ |
||
34 | private $date = null; |
||
35 | |||
36 | /** |
||
37 | * @var bool |
||
38 | * |
||
39 | * @Assert\Type("bool") |
||
40 | */ |
||
41 | private $showCountry = false; |
||
42 | |||
43 | /** |
||
44 | * @var bool |
||
45 | * |
||
46 | * @Assert\Type("bool") |
||
47 | */ |
||
48 | private $showSha1 = false; |
||
49 | |||
50 | /** |
||
51 | * @var bool |
||
52 | * |
||
53 | * @Assert\Type("bool") |
||
54 | */ |
||
55 | private $showCardType = false; |
||
56 | |||
57 | /** |
||
58 | * @var string|null |
||
59 | * |
||
60 | * @Assert\Type("string") |
||
61 | * @Assert\Length(min=1, max=250) |
||
62 | */ |
||
63 | private $subscriberRef = null; |
||
64 | |||
65 | /** |
||
66 | * @param null|string $subscriberRef |
||
67 | */ |
||
68 | public function __construct($subscriberRef = null) |
||
72 | |||
73 | /** |
||
74 | * @param int $activity |
||
75 | * |
||
76 | * @return $this |
||
77 | */ |
||
78 | final public function setActivity($activity) |
||
84 | |||
85 | /** |
||
86 | * @param \DateTime|null $date |
||
87 | * |
||
88 | * @return $this |
||
89 | */ |
||
90 | final public function setDate(\DateTime $date = null) |
||
96 | |||
97 | /** |
||
98 | * @param bool $showCountry |
||
99 | * |
||
100 | * @return $this |
||
101 | */ |
||
102 | final public function setShowCountry($showCountry) |
||
108 | |||
109 | /** |
||
110 | * @param bool $showSha1 |
||
111 | * |
||
112 | * @return $this |
||
113 | */ |
||
114 | final public function setShowSha1($showSha1) |
||
120 | |||
121 | /** |
||
122 | * @param bool $showCardType |
||
123 | * |
||
124 | * @return $this |
||
125 | */ |
||
126 | final public function setShowCardType($showCardType) |
||
132 | |||
133 | /** |
||
134 | * @return bool |
||
135 | */ |
||
136 | final protected function hasSubscriberRef() |
||
140 | |||
141 | /** |
||
142 | * @return null|string |
||
143 | */ |
||
144 | final protected function getSubscriberRef() |
||
148 | |||
149 | /** |
||
150 | * {@inheritdoc} |
||
151 | */ |
||
152 | public function getParameters() |
||
188 | } |
||
189 |
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: