GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 8bb018...93d08f )
by Lanre
02:25
created

GetPaymentData::handle()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 22
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 11
nc 4
nop 1
dl 0
loc 22
ccs 11
cts 11
cp 1
crap 3
rs 9.2
c 0
b 0
f 0
1
<?php
2
3
namespace Gbowo\Adapter\Paystack\Plugin;
4
5
use Gbowo\Adapter\Paystack\Traits\VerifyHttpStatusResponseCode;
6
use function strcmp;
7
use function GuzzleHttp\json_decode;
8
use Gbowo\Plugin\AbstractGetPaymentData;
9
use Gbowo\Adapter\Paystack\Exception\TransactionVerficationFailedException;
10
11
class GetPaymentData extends AbstractGetPaymentData
12
{
13
14
    use VerifyHttpStatusResponseCode;
15
16
    const VERIFIED_TRANSACTION = 'Verification successful';
17
18
    const INVALID_TRANSACTION = "Invalid transaction reference";
19
20
    const TRANSACTION_VERIFICATION = '/transaction/verify/';
21
22
    protected $baseUrl;
23
24
    public function __construct(string $baseUrl)
25
    {
26
        $this->baseUrl = $baseUrl;
27
    }
28
29
    /**
30
     * @param string $reference
31
     * @return mixed
32
     * @throws \Gbowo\Adapter\Paystack\Exception\TransactionVerficationFailedException
33
     */
34 4
    public function handle(string $reference) : array
35
    {
36 4
        $link = $this->baseUrl . self::TRANSACTION_VERIFICATION . $reference;
37
38 4
        $response = $this->verifyTransaction($link);
39
40 4
        $this->verifyResponse($response);
41
42 3
        $result = json_decode($response->getBody(), true);
43
44 3
        $validated = false;
45
46 3
        if (strcmp($result['message'], self::VERIFIED_TRANSACTION) === 0) {
47 2
            $validated = true;
48
        }
49
50 3
        if (false === $validated) {
51 1
            throw new TransactionVerficationFailedException(self::INVALID_TRANSACTION);
52
        }
53
54 2
        return $result["data"];
55
    }
56
57
    /**
58
     * @param string $link
59
     * @return \Psr\Http\Message\ResponseInterface
60
     */
61 4
    protected function verifyTransaction(string $link)
62
    {
63 4
        return $this->adapter->getHttpClient()
64 4
            ->get($link);
65
    }
66
}
67