Completed
Push — master ( 94c7b3...9110ec )
by ARCANEDEV
03:52
created

RedirectorManager   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 98
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 2
dl 0
loc 98
ccs 19
cts 19
cp 1
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getDefaultDriver() 0 4 1
A config() 0 4 1
A driver() 0 4 1
A createConfigDriver() 0 4 1
A createEloquentDriver() 0 6 1
A buildDriver() 0 8 1
A getConfig() 0 4 1
1
<?php namespace Arcanedev\LaravelSeo;
2
3
use Arcanedev\LaravelSeo\Contracts\RedirectorFactory;
4
use Illuminate\Support\Manager;
5
6
/**
7
 * Class     RedirectorManager
8
 *
9
 * @package  Arcanedev\LaravelSeo
10
 * @author   ARCANEDEV <[email protected]>
11
 */
12
class RedirectorManager extends Manager implements RedirectorFactory
13
{
14
    /* -----------------------------------------------------------------
15
     |  Getters & Setters
16
     | -----------------------------------------------------------------
17
     */
18
    /**
19
     * Get the default driver name.
20
     *
21
     * @return string
22
     */
23 27
    public function getDefaultDriver()
24
    {
25 27
        return $this->getConfig('redirector.default', 'config');
26
    }
27
28
    /**
29
     * Get the config repository.
30
     *
31
     * @return \Illuminate\Contracts\Config\Repository
32
     */
33 33
    protected function config()
34
    {
35 33
        return $this->app['config'];
36
    }
37
38
    /* -----------------------------------------------------------------
39
     |  Main Methods
40
     | -----------------------------------------------------------------
41
     */
42
    /**
43
     * Get a driver instance.
44
     *
45
     * @param  string  $driver
46
     *
47
     * @return \Arcanedev\LaravelSeo\Contracts\Redirector
48
     */
49 30
    public function driver($driver = null)
50
    {
51 30
        return parent::driver($driver);
52
    }
53
54
    /**
55
     * Build the config redirector driver.
56
     *
57
     * @return \Arcanedev\LaravelSeo\Redirectors\ConfigurationRedirector
58
     */
59 27
    public function createConfigDriver()
60
    {
61 27
        return $this->buildDriver('config');
62
    }
63
64
    /**
65
     * Build the eloquent redirector driver.
66
     *
67
     * @return \Arcanedev\LaravelSeo\Redirectors\EloquentRedirector
68
     */
69 3
    public function createEloquentDriver()
70
    {
71 3
        return $this->buildDriver('eloquent', [
72 3
            'model' => $this->getConfig('redirects.model'),
73 1
        ]);
74
    }
75
76
    /* -----------------------------------------------------------------
77
     |  Other Methods
78
     | -----------------------------------------------------------------
79
     */
80
    /**
81
     * Build the redirector.
82
     *
83
     * @param  string  $driver
84
     * @param  array   $extra
85
     *
86
     * @return mixed
87
     */
88 30
    private function buildDriver($driver, array $extra = [])
89
    {
90 30
        $router  = $this->app->make(\Illuminate\Contracts\Routing\Registrar::class);
91 30
        $class   = $this->getConfig("redirector.drivers.$driver.class");
92 30
        $options = $this->getConfig("redirector.drivers.$driver.options", []);
93
94 30
        return new $class($router, array_merge($extra, $options));
95
    }
96
97
    /**
98
     * Get the seo config.
99
     *
100
     * @param  string      $key
101
     * @param  mixed|null  $default
102
     *
103
     * @return mixed
104
     */
105 33
    private function getConfig($key, $default = null)
106
    {
107 33
        return $this->config()->get("seo.$key", $default);
108
    }
109
}
110