Completed
Push — master ( 2e002a...ff3a53 )
by Mario
04:03
created

HttpClientFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 3
dl 0
loc 40
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 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
    public function __construct($config, TokenInterface $token)
35
    {
36
        if (empty($config['marek_toggable']['base_uri']))
37
        {
38
            throw new InvalidArgumentException('Please provide base URI.');
39
        }
40
        $this->uri = $config['marek_toggable']['base_uri'];
41
        $this->token = $token;
42
    }
43
44
    /**
45
     * @inheritDoc
46
     */
47
    public function build()
48
    {
49
        if (!filter_var($this->uri, FILTER_VALIDATE_URL)) {
50
            throw new InvalidArgumentException('Please provide valid base URI.');
51
        }
52
53
        return new NativeHttpClient($this->uri, $this->token, new NativeArgumentsConverter(), new NativeResponseParser());
54
    }
55
}
56