1 | <?php |
||
12 | abstract class AbstractRequest implements RequestInterface |
||
13 | { |
||
14 | /** |
||
15 | * @var int |
||
16 | * |
||
17 | * @Assert\NotBlank |
||
18 | * @Enum(class="Nexy\PayboxDirect\Enum\Activity", showKeys=true) |
||
19 | */ |
||
20 | private $activity = Activity::WEB_REQUEST; |
||
21 | |||
22 | /** |
||
23 | * @var \DateTime |
||
24 | * |
||
25 | * @Assert\Type("\DateTime") |
||
26 | */ |
||
27 | private $date = null; |
||
28 | |||
29 | /** |
||
30 | * @var bool |
||
31 | * |
||
32 | * @Assert\Type("bool") |
||
33 | */ |
||
34 | private $showCountry = false; |
||
35 | |||
36 | /** |
||
37 | * @var bool |
||
38 | * |
||
39 | * @Assert\Type("bool") |
||
40 | */ |
||
41 | private $showSha1 = false; |
||
42 | |||
43 | /** |
||
44 | * @var bool |
||
45 | * |
||
46 | * @Assert\Type("bool") |
||
47 | */ |
||
48 | private $showCardType = false; |
||
49 | |||
50 | /** |
||
51 | * @var string|null |
||
52 | * |
||
53 | * @Assert\Type("string") |
||
54 | * @Assert\Length(min=1, max=250) |
||
55 | */ |
||
56 | private $subscriberRef = null; |
||
57 | |||
58 | /** |
||
59 | * @param null|string $subscriberRef |
||
60 | */ |
||
61 | public function __construct($subscriberRef = null) |
||
65 | |||
66 | /** |
||
67 | * @param int $activity |
||
68 | * |
||
69 | * @return $this |
||
70 | */ |
||
71 | final public function setActivity($activity) |
||
77 | |||
78 | /** |
||
79 | * @param \DateTime|null $date |
||
80 | * |
||
81 | * @return $this |
||
82 | */ |
||
83 | final public function setDate(\DateTime $date = null) |
||
89 | |||
90 | /** |
||
91 | * @param bool $showCountry |
||
92 | * |
||
93 | * @return $this |
||
94 | */ |
||
95 | final public function setShowCountry($showCountry) |
||
101 | |||
102 | /** |
||
103 | * @param bool $showSha1 |
||
104 | * |
||
105 | * @return $this |
||
106 | */ |
||
107 | final public function setShowSha1($showSha1) |
||
113 | |||
114 | /** |
||
115 | * @param bool $showCardType |
||
116 | * |
||
117 | * @return $this |
||
118 | */ |
||
119 | final public function setShowCardType($showCardType) |
||
125 | |||
126 | /** |
||
127 | * @return bool |
||
128 | */ |
||
129 | final protected function hasSubscriberRef() |
||
130 | { |
||
131 | return !empty($this->subscriberRef); |
||
132 | } |
||
133 | |||
134 | /** |
||
135 | * @return null|string |
||
136 | */ |
||
137 | final protected function getSubscriberRef() |
||
141 | |||
142 | /** |
||
143 | * {@inheritdoc} |
||
144 | */ |
||
145 | public function getParameters() |
||
179 | } |
||
180 |
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: