Factory::createTransport()   B
last analyzed

Complexity

Conditions 6
Paths 7

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 20
ccs 9
cts 9
cp 1
rs 8.9777
c 0
b 0
f 0
cc 6
nc 7
nop 0
crap 6
1
<?php declare(strict_types=1);
2
3
namespace Fazland\SkebbyRestClient\Transport;
4
5
use Fazland\SkebbyRestClient\Exception\RuntimeException;
6
use GuzzleHttp\Client;
7
use Http\Discovery\Exception\NotFoundException;
8
use Http\Discovery\HttpClientDiscovery;
9
use Http\Discovery\MessageFactoryDiscovery;
10
11
/**
12
 * Transport Factory.
13
 *
14
 * @author Alessandro Chitolina <[email protected]>
15
 */
16
class Factory
17
{
18
    /**
19
     * Creates the transport based on which classes are defined.
20
     *
21
     * @return TransportInterface
22
     *
23
     * @throws RuntimeException
24
     */
25 4
    public static function createTransport(): TransportInterface
26
    {
27 4
        if (class_exists(HttpClientDiscovery::class) && class_exists(MessageFactoryDiscovery::class)) {
28
            try {
29 3
                return new HttpClientTransport(HttpClientDiscovery::find(), MessageFactoryDiscovery::find());
30 2
            } catch (NotFoundException $e) {
31
                // Do nothing
32
            }
33
        }
34
35 3
        if (class_exists(Client::class)) {
36 1
            return new Guzzle6Transport();
37
        }
38
39 2
        if (extension_loaded('curl')) {
40 1
            return new CurlExtensionTransport();
41
        }
42
43 1
        throw new RuntimeException('Cannot create an HTTP transport object');
44
    }
45
}
46