Completed
Pull Request — master (#65)
by Tobias
03:21
created

HttpAsyncClientDiscovery::find()   A

Complexity

Conditions 3
Paths 6

Size

Total Lines 19
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3.0261

Importance

Changes 4
Bugs 0 Features 2
Metric Value
c 4
b 0
f 2
dl 0
loc 19
ccs 6
cts 7
cp 0.8571
rs 9.4285
cc 3
eloc 11
nc 6
nop 0
crap 3.0261
1
<?php
2
3
namespace Http\Discovery;
4
5
use Http\Client\HttpAsyncClient;
6
use Http\Discovery\Exception\DiscoveryFailedException;
7
use Http\Discovery\Exception\NotFoundException;
8
9
/**
10
 * Finds an HTTP Asynchronous Client.
11
 *
12
 * @author Joel Wurtz <[email protected]>
13
 */
14
final class HttpAsyncClientDiscovery extends ClassDiscovery
15
{
16
    /**
17
     * Finds an HTTP Async Client.
18
     *
19
     * @return HttpAsyncClient
20
     *
21
     * @throws NotFoundException
22
     */
23 1
    public static function find()
24
    {
25
        try {
26
            $asyncClient = static::findOneByType(HttpAsyncClient::class);
27
28
            // Something like this
29
            if (is_string($asyncClient)) {
30
                return new $asyncClient();
31
            }
32
33
            return $asyncClient();
34 1
        } catch (DiscoveryFailedException $e) {
35 1
            throw new NotFoundException(
36 1
                'No HTTPlug async clients found. Make sure to install a package providing "php-http/async-client-implementation". Example: "php-http/guzzle6-adapter".',
37 1
                0,
38
                $e
39 1
            );
40
        }
41
    }
42
}
43