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
Pull Request — master (#2)
by VEBER
02:01
created

Client::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 9
rs 9.6666
c 1
b 0
f 0
cc 2
eloc 5
nc 2
nop 2
1
<?php
2
3
/*
4
 * This file is part of the KongAdminApi package.
5
 *
6
 * (c) Unikorp <https://github.com/unikorp>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Unikorp\KongAdminApi;
13
14
use Http\Client\Common\HttpMethodsClient;
15
use Http\Client\Common\Plugin;
16
use Http\Client\Common\PluginClient;
17
use Http\Client\HttpClient;
18
use Http\Discovery\HttpClientDiscovery;
19
use Http\Discovery\MessageFactoryDiscovery;
20
use Http\Discovery\UriFactoryDiscovery;
21
use Http\Message\MessageFactory;
22
23
/**
24
 * client
25
 *
26
 * @author VEBER Arnaud <https://github.com/VEBERArnaud>
27
 */
28
class Client
29
{
30
    /**
31
     * http client
32
     * @var \Http\Client\HttpClient $httpClient
33
     */
34
    private $httpClient = null;
35
36
    /**
37
     * message factory
38
     * @var \Http\Message\MessageFactory $messageFactory
39
     */
40
    private $messageFactory = null;
41
42
    /**
43
     * plugins
44
     * @var array $plugins
45
     */
46
    private $plugins = [];
47
48
    /**
49
     * constructor
50
     *
51
     * @param string $baseUri
52
     * @param \Http\Client\HttpClient $httpClient
53
     */
54
    public function __construct($baseUri, HttpClient $httpClient = null)
55
    {
56
        $this->httpClient = $httpClient ?: HttpClientDiscovery::find();
57
        $this->messageFactory = MessageFactoryDiscovery::find();
58
59
        $this->addPlugin(
60
            new Plugin\AddHostPlugin(UriFactoryDiscovery::find()->createUri($baseUri))
61
        );
62
    }
63
64
    /**
65
     * api
66
     *
67
     * @param string $name
68
     *
69
     * @return \Unikorp\KongAdminApi\ApiInterface
70
     *
71
     * @throws \InvalidArgumentException
72
     */
73
    public function api($name)
74
    {
75
        switch ($name) {
76
            case 'api':
77
                return new Api\Api($this);
78
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
79
            case 'cluster':
80
                return new Api\Cluster($this);
81
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
82
            case 'consumer':
83
                return new Api\Consumer($this);
84
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
85
            case 'information':
86
                return new Api\Information($this);
87
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
88
            default:
89
                throw new \InvalidArgumentException(sprintf('Undefined api instance called: %s', $name));
90
        }
91
    }
92
93
    /**
94
     * add plugin
95
     *
96
     * @param \Http\Client\Common\Plugin $plugin
97
     *
98
     * @return void
99
     */
100
    public function addPlugin(Plugin $plugin)
101
    {
102
        $this->plugins[] = $plugin;
103
    }
104
105
    /**
106
     * get http client
107
     *
108
     * @return \Http\Client\Common\HttpMethodsClient
109
     */
110
    public function getHttpClient()
111
    {
112
        return new HttpMethodsClient(
113
            new PluginClient($this->httpClient, $this->plugins),
114
            $this->messageFactory
115
        );
116
    }
117
}
118