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 45
Duplicated Lines 40 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 18
loc 45
ccs 12
cts 12
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 5 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\Amplifypay\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\Amplifypay\Plugin
15
 */
16
class FetchPlan extends AbstractFetchPlan
17
{
18
19
    /**
20
     * @var string
21
     */
22
    protected $baseUrl;
23
24
    /**
25
     * @var array
26
     */
27
    protected $apiKeys;
28
29
    const FETCH_PLAN_RELATIVE_LINK = "/plan/:identifier";
30
31 2
    public function __construct(string $baseUrl, array $apiKeys)
32
    {
33 2
        $this->baseUrl = $baseUrl;
34 2
        $this->apiKeys= $apiKeys;
35 2
    }
36
37
    /**
38
     * @param $planIdentifier The id or string representation of the plan
39
     * @return mixed
40
     * @throws \Gbowo\Exception\InvalidHttpResponseException if the response code is not 200
41
     */
42 2 View Code Duplication
    public function handle($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...
43
    {
44 2
        $link = $this->baseUrl."?PlanId={$planIdentifier}";
45
46
        /**
47
         * @var ResponseInterface $response
48
         */
49 2
        $response = $this->adapter->getHttpClient()
50 2
            ->get($link);
51
52 2
        if (200 !== $response->getStatusCode()) {
53 1
            throw new InvalidHttpResponseException(
54 1
                "Expected 200. Got {$response->getStatusCode()}"
55
            );
56
        }
57
58 1
        return json_decode($response->getBody(), true);
59
    }
60
}
61