Manager   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 1
dl 0
loc 46
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A driver() 0 19 4
A getConfig() 0 4 1
A getDefaultDriver() 0 4 1
A getFallbackDriver() 0 4 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