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.

ChargeWithToken::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
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 GuzzleHttp\json_decode;
7
use function GuzzleHttp\json_encode;
8
use Gbowo\Plugin\AbstractChargeWithToken;
9
use Gbowo\Exception\TransactionVerficationFailedException;
10
11
class ChargeWithToken extends AbstractChargeWithToken
12
{
13
    use VerifyHttpStatusResponseCode;
14
15
    /**
16
     * The relative link for charging users
17
     * @var string
18
     */
19
    const TOKEN_CHARGE_RELATIVE_LINK = "/transaction/charge_authorization";
20
21
    const SUCCESS_MESSAGE = "Successful";
22
    /**
23
     * @var string
24
     */
25
    protected $baseUrl;
26
27 25
    public function __construct(string $baseUrl)
28
    {
29 25
        $this->baseUrl = $baseUrl;
30 25
    }
31
32 3
    public function handle(array $args) : array
33
    {
34 3
        $response = $this->chargeByToken($args);
35
36 3
        $this->verifyResponse($response);
37
38 2
        $res = json_decode($response->getBody(), true);
39
40 2
        if (strcmp($res['data']['gateway_response'], self::SUCCESS_MESSAGE) !== 0) {
41 1
            throw TransactionVerficationFailedException::createFromResponse($response);
42
        }
43
44 1
        return $res['data'];
45
    }
46
47 3 View Code Duplication
    protected function chargeByToken($data)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
48
    {
49 3
        return $this->adapter->getHttpClient()
50 3
            ->post(
51 3
                $this->baseUrl . self::TOKEN_CHARGE_RELATIVE_LINK, [
52 3
                'body' => json_encode($data)
53
                ]
54
            );
55
    }
56
}
57