Completed
Push — master ( bc3f99...52b1c2 )
by Tobias
06:03
created

PluginClientFactory::createClient()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.1481

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 4
cts 6
cp 0.6667
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 3
crap 2.1481
1
<?php
2
3
namespace Http\Client\Common;
4
5
use Http\Client\HttpAsyncClient;
6
use Http\Client\HttpClient;
7
8
/**
9
 * Factory to create PluginClient instances. Using this factory instead of calling PluginClient constructor will enable
10
 * the Symfony profiling without any configuration.
11
 *
12
 * @author Fabien Bourigault <[email protected]>
13
 */
14
final class PluginClientFactory
15
{
16
    /**
17
     * @var callable
18
     */
19
    private static $factory;
20
21
    /**
22
     * Set the factory to use.
23
     * The callable to provide must have the same arguments and return type as PluginClientFactory::createClient.
24
     * This is used by the HTTPlugBundle to provide a better Symfony integration.
25
     * Unlike the createClient method, this one is static to allow zero configuration profiling by hooking into early
26
     * application execution.
27
     *
28
     * @internal
29
     *
30
     * @param callable $factory
31
     */
32
    public static function setFactory(callable $factory)
33
    {
34
        static::$factory = $factory;
0 ignored issues
show
Comprehensibility introduced by
Since Http\Client\Common\PluginClientFactory is declared final, using late-static binding will have no effect. You might want to replace static with self instead.

Late static binding only has effect in subclasses. A final class cannot be extended anymore so late static binding cannot occurr. Consider replacing static:: with self::.

To learn more about late static binding, please refer to the PHP core documentation.

Loading history...
35
    }
36
37
    /**
38
     * @param HttpClient|HttpAsyncClient $client
39
     * @param Plugin[]                   $plugins
40
     * @param array                      $options {
41
     *
42
     *     @var string $client_name to give client a name which may be used when displaying client information  like in
43
     *         the HTTPlugBundle profiler.
44
     * }
45
     *
46
     * @see PluginClient constructor for PluginClient specific $options.
47
     *
48
     * @return PluginClient
49
     */
50 2
    public function createClient($client, array $plugins = [], array $options = [])
51
    {
52 2
        if (static::$factory) {
0 ignored issues
show
Comprehensibility introduced by
Since Http\Client\Common\PluginClientFactory is declared final, using late-static binding will have no effect. You might want to replace static with self instead.

Late static binding only has effect in subclasses. A final class cannot be extended anymore so late static binding cannot occurr. Consider replacing static:: with self::.

To learn more about late static binding, please refer to the PHP core documentation.

Loading history...
53
            $factory = static::$factory;
0 ignored issues
show
Comprehensibility introduced by
Since Http\Client\Common\PluginClientFactory is declared final, using late-static binding will have no effect. You might want to replace static with self instead.

Late static binding only has effect in subclasses. A final class cannot be extended anymore so late static binding cannot occurr. Consider replacing static:: with self::.

To learn more about late static binding, please refer to the PHP core documentation.

Loading history...
54
55
            return $factory($client, $plugins, $options);
56
        }
57
58 2
        unset($options['client_name']);
59
60 2
        return new PluginClient($client, $plugins, $options);
61
    }
62
}
63