Passed
Pull Request — master (#44)
by Baptiste
02:10
created

PluginClientBuilder   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 27
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A addPlugin() 0 5 1
A createClient() 0 12 2
1
<?php declare(strict_types=1);
2
namespace Behapi\Http;
3
4
use Http\Client\HttpClient;
5
use Http\Client\HttpAsyncClient;
6
7
use Http\Client\Common\Plugin;
8
use Http\Client\Common\PluginClient;
9
10
final class PluginClientBuilder
11
{
12
    /** @var Plugin */
13
    private $plugins;
14
15
    /** @var ?PluginClient */
16
    private $client;
17
18
    public function addPlugin(Plugin $plugin): void
19
    {
20
        $this->plugins[] = $plugin;
21
        $this->client = null;
22
    }
23
24
    public function createClient($client, array $options = []): PluginClient
25
    {
26
        if (null === $this->client) {
27
            $this->client = new PluginClient(
28
                $client,
29
                $this->plugins,
0 ignored issues
show
Documentation introduced by
$this->plugins is of type object<Http\Client\Common\Plugin>, but the function expects a array<integer,object<Http\Client\Common\Plugin>>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
30
                $options
31
            );
32
        }
33
34
        return $this->client;
35
    }
36
}
37