Completed
Pull Request — master (#121)
by Tobias
06:23 queued 05:15
created

HttpClientDiscovery   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 50%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 46
ccs 8
cts 16
cp 0.5
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A find() 0 14 2
A findPsr18Client() 0 14 2
1
<?php
2
3
namespace Http\Discovery;
4
5
use Http\Client\HttpClient;
6
use Http\Discovery\Exception\DiscoveryFailedException;
7
use Psr\Http\Client\ClientInterface;
8
9
/**
10
 * Finds an HTTP Client.
11
 *
12
 * @author Márk Sági-Kazár <[email protected]>
13
 */
14
final class HttpClientDiscovery extends ClassDiscovery
15
{
16
    /**
17
     * Finds an HTTP Client.
18
     *
19
     * @return HttpClient
20
     *
21
     * @throws Exception\NotFoundException
22
     */
23 2
    public static function find()
24
    {
25
        try {
26 2
            $client = static::findOneByType(HttpClient::class);
27 2
        } catch (DiscoveryFailedException $e) {
28 1
            throw new NotFoundException(
0 ignored issues
show
Deprecated Code introduced by
The class Http\Discovery\NotFoundException has been deprecated with message: since since version 1.0, and will be removed in 2.0. Use {@link \Http\Discovery\Exception\NotFoundException} instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
29 1
                'No HTTPlug clients found. Make sure to install a package providing "php-http/client-implementation". Example: "php-http/guzzle6-adapter".',
30 1
                0,
31
                $e
32 1
            );
33
        }
34
35 1
        return static::instantiateClass($client);
36
    }
37
38
    /**
39
     * Finds a PSR-18 HTTP Client.
40
     *
41
     * @return ClientInterface
42
     *
43
     * @throws Exception\NotFoundException
44
     */
45
    public static function findPsr18Client()
46
    {
47
        try {
48
            $client = static::findOneByType(ClientInterface::class);
49
        } catch (DiscoveryFailedException $e) {
50
            throw new \Http\Discovery\Exception\NotFoundException(
51
                'No PSR-18 clients found. Make sure to install a package providing "psr/http-client-implementation". Example: "php-http/guzzle6-adapter".',
52
                0,
53
                $e
54
            );
55
        }
56
57
        return static::instantiateClass($client);
58
    }
59
}
60