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