HttpClientFactory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
c 2
b 0
f 0
lcom 1
cbo 3
dl 0
loc 39
ccs 10
cts 10
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A build() 0 8 2
1
<?php
2
3
namespace Marek\Toggable\Factory\Http;
4
5
use Marek\Toggable\API\Security\TokenInterface;
6
use Marek\Toggable\Factory\FactoryInterface;
7
use InvalidArgumentException;
8
use Marek\Toggable\Http\Client\NativeHttpClient;
9
use Marek\Toggable\Http\Converter\NativeArgumentsConverter;
10
use Marek\Toggable\Http\Parser\NativeResponseParser;
11
12
/**
13
 * Class HttpClientFactory
14
 * @package Marek\Toggable\Factory\Http
15
 */
16
class HttpClientFactory implements FactoryInterface
17
{
18
    /**
19
     * @var string
20
     */
21
    private $uri;
22
23
    /**
24
     * @var \Marek\Toggable\API\Security\TokenInterface
25
     */
26
    private $token;
27
28
    /**
29
     * HttpClientFactory constructor.
30
     *
31
     * @param array $config
32
     * @param \Marek\Toggable\API\Security\TokenInterface $token
33
     */
34 16
    public function __construct($config, TokenInterface $token)
35
    {
36 16
        if (empty($config['marek_toggable']['base_uri'])) {
37 1
            throw new InvalidArgumentException('Please provide base URI.');
38
        }
39 15
        $this->uri = $config['marek_toggable']['base_uri'];
40 15
        $this->token = $token;
41 15
    }
42
43
    /**
44
     * @inheritDoc
45
     */
46 15
    public function build()
47
    {
48 15
        if (filter_var($this->uri, FILTER_VALIDATE_URL)) {
49 14
            return new NativeHttpClient($this->uri, $this->token, new NativeArgumentsConverter(), new NativeResponseParser());
50
        }
51
52 1
        throw new InvalidArgumentException('Please provide valid base URI.');
53
    }
54
}
55