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.

FetchAllPlans   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 39
c 0
b 0
f 0
wmc 3
lcom 1
cbo 5
ccs 13
cts 13
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A handle() 0 20 2
1
<?php
2
3
4
namespace Gbowo\Adapter\Amplifypay\Plugin;
5
6
use function GuzzleHttp\json_decode;
7
use Gbowo\Plugin\AbstractFetchAllPlans;
8
use Psr\Http\Message\ResponseInterface;
9
use Gbowo\Exception\InvalidHttpResponseException;
10
11
class FetchAllPlans extends AbstractFetchAllPlans
12
{
13
    const ALL_PLANS_RELATIVE_LINK = "/plan?merchantId=:m&apiKey=:key";
14
15
    protected $baseUrl;
16
17
    protected $apiKeys;
18
19 4
    public function __construct(string $baseUrl, array $apiKeys)
20
    {
21 4
        $this->apiKeys = $apiKeys;
22 4
        $this->baseUrl = $baseUrl;
23 4
    }
24
25
    /**
26
     * @return mixed
27
     * @throws \Gbowo\Exception\InvalidHttpResponseException if the response status code is not 200
28
     */
29 4
    public function handle()
30
    {
31 4
        $link = $this->baseUrl . str_replace(
32 4
            ":m", $this->apiKeys['merchantId'], self::ALL_PLANS_RELATIVE_LINK
33
        );
34
35 4
        $link = str_replace(":key", $this->apiKeys['apiKey'], $link);
36
37
        /**
38
         * @var ResponseInterface $response
39
         */
40 4
        $response = $this->adapter->getHttpClient()
41 4
            ->get($link);
42
43 4
        if ($response->getStatusCode() !== 200) {
44 1
            throw InvalidHttpResponseException::createFromResponse($response);
45
        }
46
47 3
        return json_decode($response->getBody(), true);
48
    }
49
}
50