Completed
Push — master ( 5f5045...66f0fe )
by Alessandro
07:07
created

Factory::createTransport()   B

Complexity

Conditions 6
Paths 7

Size

Total Lines 20
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 20
ccs 10
cts 10
cp 1
rs 8.8571
c 0
b 0
f 0
cc 6
eloc 10
nc 7
nop 0
crap 6
1
<?php
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
class Factory
12
{
13 4
    public static function createTransport()
14
    {
15 4
        if (class_exists(HttpClientDiscovery::class) && class_exists(MessageFactoryDiscovery::class)) {
16
            try {
17 4
                return new HttpClientTransport(HttpClientDiscovery::find(), MessageFactoryDiscovery::find());
18 2
            } catch (NotFoundException $e) {
19
                // Do nothing
20
            }
21 2
        }
22
23 3
        if (class_exists(Client::class)) {
24 1
            return new Guzzle6Transport();
25
        }
26
27 2
        if (extension_loaded('curl')) {
28 1
            return new CurlExtensionTransport();
29
        }
30
31 1
        throw new RuntimeException('Cannot create an HTTP transport object');
32
    }
33
}
34