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.

GetPaymentData   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 55
c 0
b 0
f 0
wmc 5
lcom 1
cbo 6
ccs 17
cts 17
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A handle() 0 22 3
A verifyTransaction() 0 5 1
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\Exception\TransactionVerficationFailedException;
10
11
class GetPaymentData extends AbstractGetPaymentData
12
{
13
    use VerifyHttpStatusResponseCode;
14
15
    const VERIFIED_TRANSACTION = 'Verification successful';
16
17
    const INVALID_TRANSACTION = "Invalid transaction reference";
18
19
    const TRANSACTION_VERIFICATION = '/transaction/verify/';
20
21
    protected $baseUrl;
22
23 25
    public function __construct(string $baseUrl)
24
    {
25 25
        $this->baseUrl = $baseUrl;
26 25
    }
27
28
    /**
29
     * @param string $reference
30
     * @return mixed
31
     * @throws \Gbowo\Adapter\Paystack\Exception\TransactionVerficationFailedException
32
     */
33 3
    public function handle(string $reference) : array
34
    {
35 3
        $link = $this->baseUrl . self::TRANSACTION_VERIFICATION . $reference;
36
37 3
        $response = $this->verifyTransaction($link);
38
39 3
        $this->verifyResponse($response);
40
41 2
        $result = json_decode($response->getBody(), true);
42
43 2
        $validated = false;
44
45 2
        if (strcmp($result['message'], self::VERIFIED_TRANSACTION) === 0) {
46 1
            $validated = true;
47
        }
48
49 2
        if (false === $validated) {
50 1
            throw TransactionVerficationFailedException::createFromResponse($response);
51
        }
52
53 1
        return $result["data"];
54
    }
55
56
    /**
57
     * @param string $link
58
     * @return \Psr\Http\Message\ResponseInterface
59
     */
60 3
    protected function verifyTransaction(string $link)
61
    {
62 3
        return $this->adapter->getHttpClient()
63 3
            ->get($link);
64
    }
65
}
66