Completed
Push — master ( 33b6d6...fd4fd0 )
by Tobias
05:39
created

PluginClientFactory::setFactory()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Http\Client\Common;
4
5
use Http\Client\HttpAsyncClient;
6
use Http\Client\HttpClient;
7
8
/**
9
 * @author Fabien Bourigault <[email protected]>
10
 */
11
final class PluginClientFactory
12
{
13
    /**
14
     * @var callable
15
     */
16
    private static $factory;
17
18
    /**
19
     * Set the factory to use.
20
     * The callable to provide must have the same arguments and return type as PluginClientFactory::createClient.
21
     * This is used by the HTTPlugBundle to provide a better Symfony integration.
22
     *
23
     * @internal
24
     *
25
     * @param callable $factory
26
     */
27
    public static function setFactory(callable $factory)
28
    {
29
        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...
30
    }
31
32
    /**
33
     * @param HttpClient|HttpAsyncClient $client
34
     * @param Plugin[]                   $plugins
35
     * @param array                      $options {
36
     *
37
     *     @var string $client_name to give client a name which may be used when displaying client information  like in
38
     *         the HTTPlugBundle profiler.
39
     * }
40
     *
41
     * @see PluginClient constructor for PluginClient specific $options.
42
     *
43
     * @return PluginClient
44
     */
45 1
    public function createClient($client, array $plugins = [], array $options = [])
46
    {
47 1
        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...
48
            $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...
49
50
            return $factory($client, $plugins, $options);
51
        }
52
53 1
        return new PluginClient($client, $plugins, $options);
54
    }
55
}
56