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

HttpClientDiscovery::findPsr18Client()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 0
cts 8
cp 0
rs 9.7998
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 6
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