Completed
Push — master ( 5b62c3...691103 )
by Tobias
14:09 queued 13:01
created

Psr18ClientDiscovery::find()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14

Duplication

Lines 14
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 14
loc 14
ccs 0
cts 13
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\Discovery\Exception\DiscoveryFailedException;
6
use Psr\Http\Client\ClientInterface;
7
8
/**
9
 * Finds a PSR-18 HTTP Client.
10
 *
11
 * @author Tobias Nyholm <[email protected]>
12
 */
13 View Code Duplication
final class Psr18ClientDiscovery extends ClassDiscovery
14
{
15
    /**
16
     * Finds a PSR-18 HTTP Client.
17
     *
18
     * @return ClientInterface
19
     *
20
     * @throws Exception\NotFoundException
21
     */
22
    public static function find()
23
    {
24
        try {
25
            $client = static::findOneByType(ClientInterface::class);
26
        } catch (DiscoveryFailedException $e) {
27
            throw new \Http\Discovery\Exception\NotFoundException(
28
                'No PSR-18 clients found. Make sure to install a package providing "psr/http-client-implementation". Example: "php-http/guzzle6-adapter".',
29
                0,
30
                $e
31
            );
32
        }
33
34
        return static::instantiateClass($client);
35
    }
36
}
37