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

HttpAsyncClientDiscovery   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 85.71%

Importance

Changes 4
Bugs 0 Features 2
Metric Value
wmc 3
c 4
b 0
f 2
lcom 0
cbo 2
dl 0
loc 29
ccs 6
cts 7
cp 0.8571
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A find() 0 19 3
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