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   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 19.57 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 9
loc 46
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A handle() 0 14 2
A chargeByToken() 9 9 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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