PluginClientFactory   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 23
ccs 0
cts 11
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A createPluginClient() 0 12 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Http\HttplugBundle\ClientFactory;
6
7
@trigger_error('The '.__NAMESPACE__.'\PluginClientFactory class is deprecated since version 1.8 and will be removed in 2.0. Use Http\Client\Common\PluginClientFactory instead.', E_USER_DEPRECATED);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
8
9
use Http\Client\Common\Plugin;
10
use Http\Client\Common\PluginClient;
11
12
/**
13
 * This factory creates a PluginClient.
14
 *
15
 * @deprecated
16
 *
17
 * @author Tobias Nyholm <[email protected]>
18
 */
19
final class PluginClientFactory
20
{
21
    /**
22
     * @param Plugin[]               $plugins
23
     * @param ClientFactory|callable $factory
24
     * @param array                  $config              config to the client factory
25
     * @param array                  $pluginClientOptions config forwarded to the PluginClient
26
     *
27
     * @return PluginClient
28
     */
29
    public static function createPluginClient(array $plugins, $factory, array $config, array $pluginClientOptions = [])
30
    {
31
        if ($factory instanceof ClientFactory) {
32
            $client = $factory->createClient($config);
33
        } elseif (is_callable($factory)) {
34
            $client = $factory($config);
35
        } else {
36
            throw new \RuntimeException(sprintf('Second argument to PluginClientFactory::createPluginClient must be a "%s" or a callable.', ClientFactory::class));
37
        }
38
39
        return new PluginClient($client, $plugins, $pluginClientOptions);
40
    }
41
}
42