Completed
Push — develop ( 991012...b60d88 )
by Jens
08:17
created

AdapterFactory   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 86.67%

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 6
c 1
b 1
f 0
lcom 1
cbo 1
dl 0
loc 42
ccs 13
cts 15
cp 0.8667
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 6 1
A __construct() 0 5 1
A getClass() 0 15 4
1
<?php
2
/**
3
 * @author @jayS-de <[email protected]>
4
 */
5
6
namespace Commercetools\Core\Client\Adapter;
7
8
use GuzzleHttp\Client;
9
use Commercetools\Core\Error\InvalidArgumentException;
10
11
class AdapterFactory
12
{
13
    protected $adapters = [];
14
15 204
    public function __construct()
16
    {
17 204
        $this->register('guzzle5', '\Commercetools\Core\Client\Adapter\Guzzle5Adapter')
18 204
            ->register('guzzle6', '\Commercetools\Core\Client\Adapter\Guzzle6Adapter');
19 204
    }
20
21
    /**
22
     * @param string $name
23
     * @param string $adapterClass
24
     * @return $this
25
     */
26 204
    public function register($name, $adapterClass)
27
    {
28 204
        $this->adapters[$name] = $adapterClass;
29
30 204
        return $this;
31
    }
32
33
    /**
34
     * @param string $name
35
     * @return string
36
     */
37 204
    public function getClass($name = null)
38
    {
39 204
        if (is_null($name)) {
40 204
            if (version_compare(Client::VERSION, '6.0.0', '>=')) {
41 204
                $name = 'guzzle6';
42
            } else {
43
                $name = 'guzzle5';
44
            }
45
        }
46 204
        if (isset($this->adapters[$name])) {
47 204
            return $this->adapters[$name];
48
        }
49
50
        throw new InvalidArgumentException();
51
    }
52
}
53