Manager::getConfig()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Laravelsms\Sms;
4
5
use InvalidArgumentException;
6
7
class Manager
8
{
9
    protected $app;
10
    protected $factories;
11
12
    public function __construct($app)
13
    {
14
        $this->app = $app;
15
        $this->factories = new Factory($app);
16
    }
17
18
    public function driver($name = null)
19
    {
20
        $factories = $this->factories->getFactories();
21
22
        if ($name == 'fallback') {
23
            $name = $this->getFallbackDriver();
24
        } else {
25
            $name = $name ?: $this->getDefaultDriver();
26
        }
27
28
        if (!array_key_exists($name, $factories)) {
29
            throw new InvalidArgumentException("Driver '$name' is not supported.");
30
        }
31
32
        $className = $factories[$name];
33
        $config = $this->getConfig($name);
34
35
        return new $className($config);
36
    }
37
38
    protected function getConfig($name)
39
    {
40
        return $this->app['config']["sms.agents.{$name}"];
41
    }
42
43
    protected function getDefaultDriver()
44
    {
45
        return $this->app['config']['sms.default'];
46
    }
47
48
    protected function getFallbackDriver()
49
    {
50
        return $this->app['config']['sms.fallback'];
51
    }
52
}
53