These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Gbowo\Adapter\Paystack\Plugin; |
||
4 | |||
5 | use function strcmp; |
||
6 | use function GuzzleHttp\json_decode; |
||
7 | use Gbowo\Plugin\AbstractGetPaymentData; |
||
8 | use Gbowo\Adapter\Paystack\Exception\TransactionVerficationFailedException; |
||
9 | |||
10 | class GetPaymentData extends AbstractGetPaymentData |
||
11 | { |
||
12 | const VERIFIED_TRANSACTION = 'Verification successful'; |
||
13 | |||
14 | const INVALID_TRANSACTION = "Invalid transaction reference"; |
||
15 | |||
16 | const TRANSACTION_VERIFICATION = '/transaction/verify/'; |
||
17 | |||
18 | protected $baseUrl; |
||
19 | |||
20 | public function __construct(string $baseUrl) |
||
21 | { |
||
22 | $this->baseUrl = $baseUrl; |
||
23 | } |
||
24 | |||
25 | /** |
||
26 | * @param string $reference |
||
27 | * @return mixed |
||
28 | * @throws \Gbowo\Adapter\Paystack\Exception\TransactionVerficationFailedException |
||
29 | */ |
||
30 | 3 | public function handle(string $reference) : array |
|
31 | { |
||
32 | 3 | $link = $this->baseUrl . self::TRANSACTION_VERIFICATION . $reference; |
|
33 | |||
34 | 3 | $result = json_decode($this->verifyTransaction($link), true); |
|
0 ignored issues
–
show
|
|||
35 | |||
36 | 3 | $validated = false; |
|
37 | |||
38 | 3 | if (strcmp($result['message'], self::VERIFIED_TRANSACTION) === 0) { |
|
39 | 2 | $validated = true; |
|
40 | } |
||
41 | |||
42 | 3 | if (false === $validated) { |
|
43 | 1 | throw new TransactionVerficationFailedException(self::INVALID_TRANSACTION); |
|
44 | } |
||
45 | |||
46 | 2 | return $result["data"]; |
|
47 | } |
||
48 | |||
49 | /** |
||
50 | * @param string $link |
||
51 | * @return \Psr\Http\Message\ResponseInterface |
||
52 | */ |
||
53 | 3 | protected function verifyTransaction(string $link) |
|
54 | { |
||
55 | 3 | return $this->adapter->getHttpClient() |
|
56 | 3 | ->get($link) |
|
57 | 3 | ->getBody(); |
|
58 | } |
||
59 | } |
||
60 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: