PluginClientFactory::createPluginClient()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 0
cts 11
cp 0
rs 9.8666
c 0
b 0
f 0
cc 3
nc 3
nop 4
crap 12
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