1 | <?php |
||
20 | class CompletePurchaseResponse extends AbstractResponse |
||
21 | { |
||
22 | 3 | public function __construct(RequestInterface $request, $data) |
|
23 | { |
||
24 | 3 | $this->request = $request; |
|
25 | 3 | $this->data = $data; |
|
26 | |||
27 | 3 | if ($this->getHash() !== $this->calculateHash()) { |
|
28 | 1 | throw new InvalidResponseException('Invalid hash'); |
|
29 | } |
||
30 | 2 | } |
|
31 | |||
32 | 3 | public function getHash() |
|
36 | |||
37 | 3 | public function calculateHash() |
|
41 | |||
42 | 1 | public function isSuccessful() |
|
43 | { |
||
44 | 1 | return $this->data['EPS_RESULT'] === 'done'; |
|
45 | } |
||
46 | |||
47 | 1 | public function getTransactionId() |
|
48 | { |
||
49 | 1 | return $this->data['EPS_TRID']; |
|
50 | } |
||
51 | |||
52 | 1 | public function getTransactionReference() |
|
53 | { |
||
54 | 1 | return $this->data['EPS_ACCNUM']; |
|
55 | } |
||
56 | |||
57 | 1 | public function getAmount() |
|
58 | { |
||
59 | 1 | return $this->data['EPS_AMOUNT']; |
|
60 | } |
||
61 | |||
62 | public function getTestMode() |
||
66 | |||
67 | 1 | public function getCurrency() |
|
68 | { |
||
69 | 1 | return $this->data['EPS_CURRENCY']; |
|
70 | } |
||
71 | } |
||
72 |
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: