1 | <?php |
||
20 | class CompletePurchaseResponse extends AbstractResponse |
||
21 | { |
||
22 | /** |
||
23 | * @param RequestInterface $request |
||
24 | * @param array $data |
||
25 | */ |
||
26 | 4 | public function __construct(RequestInterface $request, $data) |
|
44 | |||
45 | /** |
||
46 | * {@inheritdoc} |
||
47 | */ |
||
48 | 1 | public function isSuccessful() |
|
52 | |||
53 | /** |
||
54 | * {@inheritdoc} |
||
55 | * @return string |
||
56 | */ |
||
57 | 1 | public function getTransactionId() |
|
61 | |||
62 | /** |
||
63 | * {@inheritdoc} |
||
64 | * @return string |
||
65 | */ |
||
66 | 1 | public function getTransactionReference() |
|
70 | |||
71 | 4 | public function getTransactionStatus() |
|
75 | |||
76 | /** |
||
77 | * {@inheritdoc} |
||
78 | * @return string |
||
79 | */ |
||
80 | 1 | public function getAmount() |
|
84 | |||
85 | /** |
||
86 | * Get payment time. |
||
87 | * |
||
88 | * @return string |
||
89 | */ |
||
90 | 1 | public function getTime() |
|
97 | |||
98 | /** |
||
99 | * Get payment currency. |
||
100 | * |
||
101 | * @return string |
||
102 | */ |
||
103 | 1 | public function getCurrency() |
|
107 | |||
108 | /** |
||
109 | * Get test mode. |
||
110 | * |
||
111 | * @return string |
||
112 | */ |
||
113 | 3 | public function getTestMode() |
|
117 | |||
118 | /** |
||
119 | * Get payer info - name, username and id. |
||
120 | * |
||
121 | * @return string |
||
122 | */ |
||
123 | 1 | public function getPayer() |
|
127 | |||
128 | /** |
||
129 | * Get hash from request. |
||
130 | * |
||
131 | * @return string |
||
132 | */ |
||
133 | 3 | public function getHash() |
|
137 | |||
138 | /** |
||
139 | * Calculate hash to validate incoming IPN notifications. |
||
140 | * |
||
141 | * @return string |
||
142 | */ |
||
143 | 3 | public function calculateHash() |
|
177 | } |
||
178 |
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 implementation 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 interface: