Completed
Push — master ( 7e4f78...5ca817 )
by Filippo
02:47
created

ConnectionFactory::createConnector()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 15
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
c 0
b 0
f 0
rs 8.8571
cc 5
eloc 11
nc 5
nop 1
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 \DigitalOceanV2\Adapter\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
}
62