Completed
Push — master ( 15ad7c...0efd86 )
by Maik
04:38
created

HttpClientFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 66.67%

Importance

Changes 0
Metric Value
wmc 3
c 0
b 0
f 0
lcom 0
cbo 3
dl 0
loc 24
ccs 4
cts 6
cp 0.6667
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A get() 0 7 2
1
<?php
2
/**
3
 * This file is part of the PHP Generics package.
4
 *
5
 * @package Generics
6
 */
7
namespace Generics\Client;
8
9
use Generics\Socket\Url;
10
use Generics\Streams\HttpStream;
11
12
/**
13
 * This class provides a factory for http(s) clients
14
 *
15
 * @author Maik Greubel <[email protected]>
16
 */
17
final class HttpClientFactory
18
{
19
20
    private function __construct()
21
    {
22
        // Nothing
23
    }
24
25
    /**
26
     * Create a new instance of Http(s) client for given url
27
     *
28
     * @param Url $url
29
     *            The url to create a http(s) client instance for
30
     *            
31
     * @return HttpStream
32
     */
33 2
    public static function get(Url $url): HttpStream
34
    {
35 2
        if ($url->getScheme() === 'https') {
36 1
            return new HttpsClient($url);
37
        }
38 1
        return new HttpClient($url);
39
    }
40
}