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

ConfigServiceProvider::configureEmailRecipients()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 2
eloc 4
nc 2
nop 0
dl 0
loc 8
rs 9.4285
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