Completed
Push — master ( 217056...f710b9 )
by Tobias
12:16
created

PluginClientFactory::createPluginClient()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 8

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.4285
c 0
b 0
f 0
cc 3
eloc 8
nc 3
nop 4
crap 12
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 17 and the first side effect is on line 5.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

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