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
01:51
created

Client::addPlugin()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 1
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
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
22
/**
23
 * client
24
 *
25
 * @author VEBER Arnaud <https://github.com/VEBERArnaud>
26
 */
27
class Client
28
{
29
    /**
30
     * http client
31
     * @var \Http\Client\HttpClient $httpClient
32
     */
33
    private $httpClient = null;
34
35
    /**
36
     * message factory
37
     * @var \Http\Message\MessageFactory $messageFactory
38
     */
39
    private $messageFactory = null;
40
41
    /**
42
     * plugins
43
     * @var array $plugins
44
     */
45
    private $plugins = [];
46
47
    /**
48
     * constructor
49
     *
50
     * @param string $baseUri
51
     * @param \Http\Client\HttpClient $httpClient
52
     */
53 3
    public function __construct($baseUri, HttpClient $httpClient = null)
54
    {
55 3
        $this->httpClient = $httpClient ?: HttpClientDiscovery::find();
56 3
        $this->messageFactory = MessageFactoryDiscovery::find();
57
58 3
        $this->plugins[] = new Plugin\AddHostPlugin(UriFactoryDiscovery::find()->createUri($baseUri));
59 3
    }
60
61
    /**
62
     * document
63
     *
64
     * @param string $name
65
     *
66
     * @return \Unikorp\KongAdminApi\DocumentInterface
67
     *
68
     * @throws \InvalidArgumentException
69
     */
70 6
    public function document($name)
71
    {
72
        switch ($name) {
73 6
            case 'api':
74 1
                return new Document\Api($this);
75 5
            case 'cluster':
76 1
                return new Document\Cluster($this);
77 4
            case 'consumer':
78 1
                return new Document\Consumer($this);
79 3
            case 'information':
80 1
                return new Document\Information($this);
81 2
            case 'plugin':
82 1
                return new Document\Plugin($this);
83
            default:
84 1
                throw new \InvalidArgumentException(sprintf('Undefined document instance called: %s', $name));
85
        }
86
    }
87
88
    /**
89
     * add plugin
90
     *
91
     * @param \Http\Client\Common\Plugin $plugin
92
     *
93
     * @return void
94
     */
95 1
    public function addPlugin(Plugin $plugin)
96
    {
97 1
        $this->plugins[] = $plugin;
98 1
    }
99
100
    /**
101
     * get http client
102
     *
103
     * @return \Http\Client\Common\HttpMethodsClient
104
     */
105 1
    public function getHttpClient()
106
    {
107 1
        return new HttpMethodsClient(
108 1
            new PluginClient($this->httpClient, $this->plugins),
109 1
            $this->messageFactory
110
        );
111
    }
112
}
113