1 | <?php |
||
12 | class WebservicePurchaseResponse extends AbstractResponse |
||
13 | { |
||
14 | /** @var string */ |
||
15 | protected $returnSignature; |
||
16 | /** @var boolean */ |
||
17 | protected $usingUpcaseResponse = false; |
||
18 | |||
19 | /** |
||
20 | * Constructor |
||
21 | * |
||
22 | * @param RequestInterface $request the initiating request. |
||
23 | * @param mixed $data |
||
24 | * |
||
25 | * @throws InvalidResponseException If resopnse format is incorrect, data is missing, or signature does not match |
||
26 | */ |
||
27 | 13 | public function __construct(RequestInterface $request, $data) |
|
81 | |||
82 | 6 | public function isSuccessful() |
|
94 | |||
95 | /** |
||
96 | * Helper method to get a specific response parameter if available. |
||
97 | * |
||
98 | * @param string $key The key to look up |
||
99 | * |
||
100 | * @return null|mixed |
||
101 | */ |
||
102 | 9 | protected function getKey($key) |
|
109 | |||
110 | /** |
||
111 | * Get the authorisation code if available. |
||
112 | * |
||
113 | * @return null|string |
||
114 | */ |
||
115 | 3 | public function getTransactionReference() |
|
119 | |||
120 | /** |
||
121 | * Get the merchant response message if available. |
||
122 | * |
||
123 | * @return null|string |
||
124 | */ |
||
125 | 6 | public function getMessage() |
|
129 | |||
130 | /** |
||
131 | * Get the merchant data if available. |
||
132 | * |
||
133 | * @return null|string |
||
134 | */ |
||
135 | 1 | public function getMerchantData() |
|
139 | |||
140 | /** |
||
141 | * Get the card country if available. |
||
142 | * |
||
143 | * @return null|string ISO 3166-1 (3-digit numeric) format, if supplied |
||
144 | */ |
||
145 | 1 | public function getCardCountry() |
|
149 | } |
||
150 |
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: