Completed
Push — master ( 955d05...19c28e )
by David
03:37
created

src/PluginClientFactory.php (3 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Http\Client\Common;
4
5
use Http\Client\HttpAsyncClient;
6
use Http\Client\HttpClient;
7
use Psr\Http\Client\ClientInterface;
8
9
/**
10
 * Factory to create PluginClient instances. Using this factory instead of calling PluginClient constructor will enable
11
 * the Symfony profiling without any configuration.
12
 *
13
 * @author Fabien Bourigault <[email protected]>
14
 */
15
final class PluginClientFactory
16
{
17
    /**
18
     * @var callable
19
     */
20
    private static $factory;
21
22
    /**
23
     * Set the factory to use.
24
     * The callable to provide must have the same arguments and return type as PluginClientFactory::createClient.
25
     * This is used by the HTTPlugBundle to provide a better Symfony integration.
26
     * Unlike the createClient method, this one is static to allow zero configuration profiling by hooking into early
27
     * application execution.
28
     *
29
     * @internal
30
     *
31
     * @param callable $factory
32
     */
33
    public static function setFactory(callable $factory)
34
    {
35
        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...
36
    }
37
38
    /**
39
     * @param HttpClient|HttpAsyncClient|ClientInterface $client
40
     * @param Plugin[]                                   $plugins
41
     * @param array                                      $options {
42
     *
43
     *     @var string $client_name to give client a name which may be used when displaying client information  like in
44
     *         the HTTPlugBundle profiler.
45
     * }
46
     *
47
     * @see PluginClient constructor for PluginClient specific $options.
48
     *
49
     * @return PluginClient
50
     */
51 2
    public function createClient($client, array $plugins = [], array $options = [])
52
    {
53 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...
54
            $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...
55
56
            return $factory($client, $plugins, $options);
57
        }
58
59 2
        unset($options['client_name']);
60
61 2
        return new PluginClient($client, $plugins, $options);
62
    }
63
}
64