ConnectionFactory   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 4
dl 0
loc 40
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A make() 0 4 1
B createConnector() 0 15 5
1
<?php
2
3
/*
4
 * This file is part of Laravel SMSFactor.
5
 *
6
 * (c) Filippo Galante <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace IlGala\SMSFactor\Connectors;
13
14
use InvalidArgumentException;
15
16
/**
17
 * This is the adapter connection factory class.
18
 *
19
 * @author Filippo Galante <[email protected]>
20
 */
21
class ConnectionFactory
22
{
23
24
    /**
25
     * Establish an adapter connection.
26
     *
27
     * @param array $config
28
     *
29
     * @return \IlGala\SMSFactor\Adapters\AdapterInterface
30
     */
31
    public function make(array $config)
32
    {
33
        return $this->createConnector($config)->connect($config);
34
    }
35
36
    /**
37
     * Create a connector instance based on the configuration.
38
     *
39
     * @param array $config
40
     *
41
     * @throws \InvalidArgumentException
42
     *
43
     * @return \GrahamCampbell\Manager\ConnectorInterface
44
     */
45
    public function createConnector(array $config)
46
    {
47
        if (!isset($config['driver'])) {
48
            throw new InvalidArgumentException('A driver must be specified.');
49
        }
50
        switch ($config['driver']) {
51
            case 'buzz':
52
                return new BuzzConnector();
53
            case 'guzzle':
54
                return new GuzzleConnector();
55
            case 'guzzlehttp':
56
                return new GuzzleHttpConnector();
57
        }
58
        throw new InvalidArgumentException("Unsupported driver [{$config['driver']}].");
59
    }
60
}
61