Completed
Pull Request — master (#29)
by Sebastian
10:22
created

ConfigServiceProvider   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 10
c 4
b 0
f 0
lcom 1
cbo 2
dl 0
loc 46
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 6 1
A configureAuthorization() 0 7 2
B configureCacheProvider() 0 19 5
A configureEmailRecipients() 0 8 2
1
<?php
2
3
namespace App\Providers;
4
5
use Exception;
6
use Illuminate\Support\ServiceProvider;
7
use Illuminate\Cache\MemcachedConnector;
8
9
class ConfigServiceProvider extends ServiceProvider
10
{
11
    public function register()
12
    {
13
        $this->configureAuthorization();
14
        $this->configureCacheProvider();
15
        $this->configureEmailRecipients();
16
    }
17
18
    protected function configureAuthorization()
19
    {
20
        config()->set(
21
            'laravel-authorize.login_url',
22
            request()->isFront() ? 'login' : 'blender/login'
23
        );
24
    }
25
26
    protected function configureCacheProvider()
27
    {
28
        if (
29
            app()->environment() === 'production' ||
30
            config()->get('cache.default') !== 'memcached'
31
        ) {
32
            return;
33
        }
34
35
        try {
36
            if (!class_exists('Memcached')) {
37
                throw new Exception();
38
            }
39
40
            (new MemcachedConnector())->connect(config('cache.stores.memcached.servers'));
41
        } catch (Exception $e) {
42
            config()->set('cache.default', 'array');
43
        }
44
    }
45
46
    protected function configureEmailRecipients()
47
    {
48
        if (app()->environment() === 'production') {
49
            return;
50
        }
51
52
        config()->set('mail.questionFormRecipients', ['[email protected]']);
53
    }
54
}
55