1 | <?php |
||
21 | class CompletePurchaseResponse extends AbstractResponse |
||
22 | { |
||
23 | /** |
||
24 | * @param RequestInterface $request |
||
25 | * @param array $data |
||
26 | */ |
||
27 | public function __construct(RequestInterface $request, $data) |
||
44 | |||
45 | /** |
||
46 | * {@inheritdoc} |
||
47 | */ |
||
48 | public function isSuccessful() |
||
52 | |||
53 | /** |
||
54 | * {@inheritdoc} |
||
55 | * @return string |
||
56 | */ |
||
57 | public function getTransactionId() |
||
61 | |||
62 | /** |
||
63 | * {@inheritdoc} |
||
64 | * @return string |
||
65 | */ |
||
66 | public function getTransactionReference() |
||
70 | |||
71 | public function getTransactionStatus() |
||
75 | |||
76 | /** |
||
77 | * {@inheritdoc} |
||
78 | * @return string |
||
79 | */ |
||
80 | public function getAmount() |
||
84 | |||
85 | /** |
||
86 | * Get payment time. |
||
87 | * |
||
88 | * @return string |
||
89 | */ |
||
90 | public function getTime() |
||
94 | |||
95 | /** |
||
96 | * Get test mode. |
||
97 | * |
||
98 | * @return string |
||
99 | */ |
||
100 | public function getTestMode() |
||
104 | |||
105 | /** |
||
106 | * Get payer info - name, username and id. |
||
107 | * |
||
108 | * @return string |
||
109 | */ |
||
110 | public function getPayer() |
||
114 | |||
115 | /** |
||
116 | * Get hash from request. |
||
117 | * |
||
118 | * @return string |
||
119 | */ |
||
120 | public function getHash() |
||
124 | |||
125 | /** |
||
126 | * Calculate hash to validate incoming IPN notifications. |
||
127 | * |
||
128 | * @return string |
||
129 | */ |
||
130 | public function calculateHash() |
||
165 | } |
||
166 |
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: