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.
Passed
Push — develop ( 7475b4...faeb8a )
by A s m
03:14
created

Multicoin::setPlugins()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 13
nc 1
nop 1
dl 0
loc 18
rs 9.8333
c 0
b 0
f 0
1
<?php
2
3
namespace Multicoin\Api;
4
5
use Multicoin\Api\Traits\User;
6
use Multicoin\Api\Traits\Address;
7
use Multicoin\Api\Traits\Invoice;
8
use Multicoin\Api\Traits\Currency;
9
use Multicoin\Api\Service\ApiClient;
10
use Multicoin\Api\Traits\Transaction;
11
use Http\Message\Authentication\Bearer;
12
use Http\Client\Common\Plugin\ErrorPlugin;
13
use Http\Client\Common\Plugin\RetryPlugin;
14
use Http\Client\Common\Plugin\DecoderPlugin;
15
use Http\Client\Common\Plugin\HeaderSetPlugin;
16
use Http\Client\Common\Plugin\QueryDefaultsPlugin;
17
use Http\Client\Common\Plugin\AuthenticationPlugin;
18
19
class Multicoin
20
{
21
    use Address, Invoice, Transaction;
22
    use User, Currency;
23
24
    public $coin;
25
    protected $client;
0 ignored issues
show
Coding Style introduced by
Protected member variable "client" must contain a leading underscore
Loading history...
26
27
    protected $config;
0 ignored issues
show
Coding Style introduced by
Protected member variable "config" must contain a leading underscore
Loading history...
28
29
    public function __construct(array $config = [], $client = null)
30
    {
31
        $this->config = $config;
32
        $this->coin = $config['coin'];
33
        $this->client = $client ?: $this->setClient();
34
        //   $this->setAuth($this->config['key']);
35
     //   parent::__construct($this->setUrl($this->config['url']));
36
    }
37
38
    public function buildQueryParam(array $default, array $param = [])
39
    {
40
        //$data = array_filter(array_merge($default, $param), 'strlen');
41
        $params = array_merge($default, $param);
42
43
        return http_build_query($params);
44
    }
45
46
    public function buildUrl($url)
47
    {
48
        return '/'.trim($this->coin, '/').$url;
49
    }
50
51
    public function setAuth($apiKey = null)
52
    {
53
        if (null === $apiKey) {
54
            $apiKey = config('multicoin.api_token');
55
        }
56
57
        $authentication = new Bearer($apiKey);
58
        $authenticationPlugin = new AuthenticationPlugin($authentication);
59
60
        return $authenticationPlugin;
61
62
        return [
0 ignored issues
show
Unused Code introduced by
return array($authenticationPlugin) is not reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
63
            $authenticationPlugin,
64
        ];
65
    }
66
67
    public function setClient()
68
    {
69
        $plugins = $this->setPlugins($this->config['api_token']);
70
        $baseUrl = $this->setUrl($this->config['url']);
71
72
        return new ApiClient($baseUrl, $plugins);
73
    }
74
75
    public function setPlugins($apiKey = null)
76
    {
77
        $auth = $this->setAuth($apiKey);
78
        $decoderPlugin = new DecoderPlugin();
79
        $headerSetPlugin = new HeaderSetPlugin([
80
            'Accept' => 'application/json',
81
        ]);
82
        $queryDefaultsPlugin = new QueryDefaultsPlugin([
83
            'currency' => 'btc',
84
        ]);
85
86
        return [
87
            $auth,
88
            $decoderPlugin,
89
            $headerSetPlugin,
90
            $queryDefaultsPlugin,
91
            new RetryPlugin(),
92
            new ErrorPlugin(),
93
        ];
94
    }
95
96
    public function setUrl($url = null)
97
    {
98
        if (null === $url) {
99
            return config('multicoin.url');
100
        }
101
102
        return $url;
103
    }
104
}
105