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