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 ( 912ff7...0b7f7f )
by Lanre
05:08
created

PaystackAdapter::getHttpClient()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
namespace Gbowo\Adapter\Paystack;
4
5
use GuzzleHttp\Client;
6
use function Gbowo\env;
7
use Gbowo\Traits\Pluggable;
8
use Gbowo\Contract\Adapter\AdapterInterface;
9
use function GuzzleHttp\json_decode;
10
use Psr\Http\Message\ResponseInterface;
11
use Gbowo\Adapter\Paystack\Traits\Payable;
12
use Gbowo\Adapter\Paystack\Plugin\GetPaymentData;
13
use Gbowo\Adapter\Paystack\Plugin\ChargeWithToken;
14
15
/**
16
 * @method findCustomer(int $customerId)
17
 * @method getPaymentData(string $transactionReference)
18
 * @method chargeWithToken(array $data)
19
 * @author Lanre Adelowo <[email protected]>
20
 * Class PaystackAdapter
21
 * @package Gbowo\Adapter\Paystack
22
 */
23
class PaystackAdapter implements AdapterInterface
24
{
25
26
    use Pluggable, Payable;
27
28
    /**
29
     * @var string
30
     */
31
    const API_LINK = 'https://api.paystack.co';
32
33
    /**
34
     * @var \GuzzleHttp\Client
35
     */
36
    protected $httpClient;
37
38
    /**
39
     * The Api link for paystack
40
     * @var string
41
     */
42
    protected $baseUrl;
43
44
    /**
45
     * PaystackAdapter constructor.
46
     * @param \GuzzleHttp\Client|null $client
47
     */
48 13
    public function __construct(Client $client = null)
49
    {
50 13
        $this->baseUrl = self::API_LINK;
51 13
        $this->httpClient = $client ?? $this->setHttpClient(env("PAYSTACK_SECRET_KEY"));
0 ignored issues
show
Security Bug introduced by
It seems like \Gbowo\env('PAYSTACK_SECRET_KEY') targeting Gbowo\env() can also be of type false; however, Gbowo\Adapter\Paystack\P...dapter::setHttpClient() does only seem to accept string, did you maybe forget to handle an error condition?
Loading history...
52 13
        $this->registerPlugins();
53 13
    }
54
55 13
    protected function registerPlugins()
56
    {
57 13
        $this->addPlugin(new GetPaymentData($this->baseUrl))
58 13
            ->addPlugin(new ChargeWithToken($this->baseUrl));
59 13
    }
60
61
    /**
62
     * @param array $data
63
     * @return string The authorization url to render the secure payment gateway.
64
     */
65 3
    public function charge(array $data)
66
    {
67
68 3
        $response = $this->decodeResponse(
69 3
            $this->authorizeTransaction("/transaction/initialize", $data),
70 2
            true
71
        );
72
73 2
        return $response['data']['authorization_url'];
74
    }
75
76
    /**
77
     * @param \Psr\Http\Message\ResponseInterface $response
78
     * @param bool                                $associative
79
     * @return mixed
80
     */
81 2
    protected function decodeResponse(ResponseInterface $response, $associative = false)
82
    {
83 2
        return json_decode($response->getBody(), $associative);
84
    }
85
86
    /**
87
     * @return \GuzzleHttp\Client
88
     */
89 8
    public function getHttpClient(): Client
90
    {
91 8
        return $this->httpClient;
92
    }
93
94
    /**
95
     * @codeCoverageIgnore
96
     * @param string $token
97
     * @return \GuzzleHttp\Client
98
     */
99 View Code Duplication
    protected function setHttpClient(string $token) : Client
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...
100
    {
101
        return new Client([
102
            'base_uri' => $this->baseUrl,
103
            'headers' => [
104
                'Authorization' => 'Bearer ' . $token,
105
                'Content-Type' => 'application/json',
106
                'Accept' => 'application/json'
107
            ]
108
        ]);
109
    }
110
}
111