Notification Setup Error

We have detected an error in your notification set-up (Event-ID dab39dc24f564ec7bd4628d1305fd03c). Currently, we cannot inform you about inspection progress. Please check that the user 557058:bca11929-8c2d-43f2-8a82-c5416880d395 still has access to your repository or update the API account.

Completed
Pull Request — develop ( #41 )
by
unknown
27:26 queued 12:27
created

HttpPluginClientBuilder   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 4
dl 0
loc 56
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 3
A addPlugin() 0 5 1
A removePlugin() 0 9 3
A getHttpClient() 0 11 2
A getMessageFactory() 0 4 1
1
<?php
2
3
namespace Bitbucket\API\Http;
4
5
use Http\Client\Common\HttpMethodsClient;
6
use Http\Client\Common\Plugin;
7
use Http\Client\Common\PluginClient;
8
use Http\Client\HttpClient;
9
use Http\Discovery\HttpClientDiscovery;
10
use Http\Discovery\MessageFactoryDiscovery;
11
use Http\Message\MessageFactory;
12
use Http\Message\RequestFactory;
13
14
class HttpPluginClientBuilder
15
{
16
    /** @var HttpClient */
17
    private $httpClient;
18
    /** @var HttpMethodsClient|null */
19
    private $pluginClient;
20
    /** @var MessageFactory */
21
    private $messageFactory;
22
    /** @var Plugin[] */
23
    private $plugins = [];
24
25
    public function __construct(HttpClient $httpClient = null, MessageFactory $messageFactory = null)
26
    {
27
        $this->httpClient = $httpClient ?: HttpClientDiscovery::find();
28
        $this->messageFactory = $messageFactory ?: MessageFactoryDiscovery::find();
29
    }
30
31
    public function addPlugin(Plugin $plugin)
32
    {
33
        $this->plugins[] = $plugin;
34
        $this->pluginClient = null;
35
    }
36
37
    /**
38
     * @param string $pluginClass
39
     */
40
    public function removePlugin($pluginClass)
41
    {
42
        foreach ($this->plugins as $idx => $plugin) {
43
            if ($plugin instanceof $pluginClass) {
44
                unset($this->plugins[$idx]);
45
                $this->pluginClient = null;
46
            }
47
        }
48
    }
49
50
    /**
51
     * @return HttpMethodsClient
52
     */
53
    public function getHttpClient()
54
    {
55
        if (!$this->pluginClient) {
56
            $this->pluginClient = new HttpMethodsClient(
57
                new PluginClient($this->httpClient, $this->plugins),
58
                $this->messageFactory
59
            );
60
        }
61
62
        return $this->pluginClient;
63
    }
64
65
    public function getMessageFactory()
66
    {
67
        return $this->messageFactory;
68
    }
69
}
70