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 ( 65dc27...4e2c47 )
by Lanre
05:32
created

FetchPlan   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 42
Duplicated Lines 42.86 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 18
loc 42
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A handle() 18 18 2

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
4
namespace Gbowo\Adapter\Paystack\Plugin;
5
6
use Gbowo\Plugin\AbstractFetchPlan;
7
use function GuzzleHttp\json_decode;
8
use Psr\Http\Message\ResponseInterface;
9
use Gbowo\Exception\InvalidHttpResponseException;
10
11
/**
12
 * @author Lanre Adelowo <[email protected]>
13
 * Class FetchPlan
14
 * @package Gbowo\Adapter\Paystack\Plugin
15
 */
16
class FetchPlan extends AbstractFetchPlan
17
{
18
19
    /**
20
     * @var string The relative link for fetching a certain plan
21
     */
22
    const FETCH_PLAN_LINK = '/plan/:identifier';
23
24
    /**
25
     * @var string Paystack's base Url
26
     */
27
    protected $baseUrl;
28
29 2
    public function __construct(string $baseUrl)
30
    {
31 2
        $this->baseUrl = $baseUrl;
32 2
    }
33
34
    /**
35
     * @param string $planIdentifier The unique plan identifier
36
     * @return mixed
37
     * @throws \Gbowo\Exception\InvalidHttpResponseException if ann http response of 200 isn't returned
38
     */
39 2 View Code Duplication
    public function handle(string $planIdentifier)
1 ignored issue
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...
40
    {
41 2
        $link = $this->baseUrl . str_replace(":identifier", $planIdentifier, self::FETCH_PLAN_LINK);
42
43
        /**
44
         * @var ResponseInterface $response
45
         */
46 2
        $response = $this->adapter->getHttpClient()
47 2
            ->get($link);
48
49 2
        if (200 !== $response->getStatusCode()) {
50 1
            throw new InvalidHttpResponseException(
51 1
                "Expected 200. Got {$response->getStatusCode()} instead"
52
            );
53
        }
54
55 1
        return json_decode($response->getBody(), true)['data'];
56
    }
57
}
58