1 | <?php |
||
20 | class CompletePurchaseResponse extends AbstractResponse |
||
21 | { |
||
22 | /** |
||
23 | * @return AbstractRequest|RequestInterface |
||
24 | */ |
||
25 | public function getRequest() |
||
29 | |||
30 | /** |
||
31 | * @param RequestInterface $request |
||
32 | * @param array $data |
||
33 | * @throws InvalidResponseException when the request validation fails |
||
34 | */ |
||
35 | 4 | public function __construct(RequestInterface $request, $data) |
|
53 | |||
54 | /** |
||
55 | * {@inheritdoc} |
||
56 | */ |
||
57 | 1 | public function isSuccessful() |
|
61 | |||
62 | /** |
||
63 | * {@inheritdoc} |
||
64 | * @return string |
||
65 | */ |
||
66 | 1 | public function getTransactionId() |
|
70 | |||
71 | /** |
||
72 | * {@inheritdoc} |
||
73 | * @return string |
||
74 | */ |
||
75 | 1 | public function getTransactionReference() |
|
79 | |||
80 | 4 | public function getTransactionStatus() |
|
84 | |||
85 | /** |
||
86 | * {@inheritdoc} |
||
87 | * @return string |
||
88 | */ |
||
89 | 1 | public function getAmount() |
|
93 | |||
94 | /** |
||
95 | * Get payment time. |
||
96 | * |
||
97 | * @return string |
||
98 | */ |
||
99 | 1 | public function getTime() |
|
106 | |||
107 | /** |
||
108 | * Get payment currency. |
||
109 | * |
||
110 | * @return string |
||
111 | */ |
||
112 | 1 | public function getCurrency() |
|
116 | |||
117 | /** |
||
118 | * Get test mode. |
||
119 | * |
||
120 | * @return string |
||
121 | */ |
||
122 | 3 | public function getTestMode() |
|
126 | |||
127 | /** |
||
128 | * Get payer info - name, username and id. |
||
129 | * |
||
130 | * @return string |
||
131 | */ |
||
132 | 1 | public function getPayer() |
|
136 | |||
137 | /** |
||
138 | * Get hash from request. |
||
139 | * |
||
140 | * @return string |
||
141 | */ |
||
142 | 3 | public function getHash() |
|
146 | |||
147 | /** |
||
148 | * Calculate hash to validate incoming IPN notifications. |
||
149 | * |
||
150 | * @return string |
||
151 | */ |
||
152 | 3 | public function calculateHash() |
|
186 | } |
||
187 |
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: