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
03:58
created

Client::getHttpClient()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
crap 1
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 3
    public function __construct($baseUri, HttpClient $httpClient = null)
55
    {
56 3
        $this->httpClient = $httpClient ?: HttpClientDiscovery::find();
57 3
        $this->messageFactory = MessageFactoryDiscovery::find();
58
59 3
        $this->plugins[] = new Plugin\AddHostPlugin(UriFactoryDiscovery::find()->createUri($baseUri));
60 3
    }
61
62
    /**
63
     * api
64
     *
65
     * @param string $name
66
     *
67
     * @return \Unikorp\KongAdminApi\ApiInterface
68
     *
69
     * @throws \InvalidArgumentException
70
     */
71 6
    public function api($name)
72
    {
73
        switch ($name) {
74 6
            case 'api':
75 1
                return new Api\Api($this);
76 5
            case 'cluster':
77 1
                return new Api\Cluster($this);
78 4
            case 'consumer':
79 1
                return new Api\Consumer($this);
80 3
            case 'information':
81 1
                return new Api\Information($this);
82 2
            case 'plugin':
83 1
                return new Api\Plugin($this);
84
            default:
85 1
                throw new \InvalidArgumentException(sprintf('Undefined api instance called: %s', $name));
86
        }
87
    }
88
89
    /**
90
     * add plugin
91
     *
92
     * @param \Http\Client\Common\Plugin $plugin
93
     *
94
     * @return void
95
     */
96 1
    public function addPlugin(Plugin $plugin)
97
    {
98 1
        $this->plugins[] = $plugin;
99 1
    }
100
101
    /**
102
     * get http client
103
     *
104
     * @return \Http\Client\Common\HttpMethodsClient
105
     */
106 1
    public function getHttpClient()
107
    {
108 1
        return new HttpMethodsClient(
109 1
            new PluginClient($this->httpClient, $this->plugins),
110 1
            $this->messageFactory
111
        );
112
    }
113
}
114