ConfiguredClientsStrategy   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 43
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getCandidates() 0 16 5
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Http\HttplugBundle\Discovery;
6
7
use Http\Client\HttpAsyncClient;
8
use Http\Client\HttpClient;
9
use Http\Discovery\HttpClientDiscovery;
10
use Http\Discovery\Strategy\DiscoveryStrategy;
11
12
/**
13
 * A strategy that provide clients configured with HTTPlug bundle. With help from this strategy
14
 * we can use the web debug toolbar for clients found with the discovery.
15
 *
16
 * @author Tobias Nyholm <[email protected]>
17
 */
18
class ConfiguredClientsStrategy implements DiscoveryStrategy
19
{
20
    /**
21
     * @var HttpClient
22
     */
23
    private static $client;
24
25
    /**
26
     * @var HttpAsyncClient
27
     */
28
    private static $asyncClient;
29
30
    /**
31
     * @param HttpClient      $httpClient
32
     * @param HttpAsyncClient $asyncClient
33
     */
34 6
    public function __construct(HttpClient $httpClient = null, HttpAsyncClient $asyncClient = null)
35
    {
36 6
        self::$client = $httpClient;
37 6
        self::$asyncClient = $asyncClient;
38 6
        HttpClientDiscovery::clearCache();
39 6
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44 16
    public static function getCandidates($type)
45
    {
46 16
        if (HttpClient::class === $type && null !== self::$client) {
47
            return [['class' => function () {
48 4
                return self::$client;
49 4
            }]];
50
        }
51
52 16
        if (HttpAsyncClient::class === $type && null !== self::$asyncClient) {
53
            return [['class' => function () {
54 6
                return self::$asyncClient;
55 6
            }]];
56
        }
57
58 13
        return [];
59
    }
60
}
61