1 | <?php |
||
20 | class CompletePurchaseResponse extends AbstractResponse |
||
21 | 3 | { |
|
22 | public function __construct(CompletePurchaseRequest $request, $data) |
||
31 | |||
32 | /** |
||
33 | * Whether the payment is successful. |
||
34 | * @return boolean |
||
35 | 1 | */ |
|
36 | public function isSuccessful() |
||
40 | |||
41 | /** |
||
42 | * Whether the payment is test. |
||
43 | * XXX TODO. |
||
44 | * @return boolean |
||
45 | 1 | */ |
|
46 | public function getTestMode() |
||
50 | |||
51 | /** |
||
52 | * {@inheritdoc} |
||
53 | * @return string |
||
54 | 1 | */ |
|
55 | public function getTransactionId() |
||
59 | |||
60 | /** |
||
61 | * {@inheritdoc} |
||
62 | * @return string |
||
63 | 1 | */ |
|
64 | public function getTransactionReference() |
||
68 | |||
69 | /** |
||
70 | * {@inheritdoc} |
||
71 | * @return string |
||
72 | 1 | */ |
|
73 | public function getAmount() |
||
77 | |||
78 | /** |
||
79 | * Returns the currency. |
||
80 | * @return string |
||
81 | 1 | */ |
|
82 | public function getCurrency() |
||
86 | |||
87 | /** |
||
88 | * Returns the payer ID. |
||
89 | * @return string |
||
90 | 1 | */ |
|
91 | public function getPayer() |
||
95 | |||
96 | /** |
||
97 | * Returns the payment date. |
||
98 | * @return string |
||
99 | 1 | */ |
|
100 | public function getTime() |
||
104 | |||
105 | /** |
||
106 | * Get hash from request. |
||
107 | * |
||
108 | * @return string |
||
109 | 3 | */ |
|
110 | public function getHash() |
||
114 | |||
115 | /** |
||
116 | * Calculate hash to validate incoming confirmation. |
||
117 | * |
||
118 | * @return string |
||
119 | 3 | */ |
|
120 | public function calculateHash() |
||
132 | } |
||
133 |
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: