Completed
Push — master ( 1b3dfc...3e655f )
by Elf
05:19 queued 02:52
created

ConfigServiceProvider   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 76.32%

Importance

Changes 0
Metric Value
dl 0
loc 86
ccs 29
cts 38
cp 0.7632
rs 10
c 0
b 0
f 0
wmc 16
lcom 1
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 4 1
A register() 0 8 2
1
<?php
2
3
namespace App\Providers;
4
5
use Illuminate\Support\ServiceProvider;
6
7
class ConfigServiceProvider extends ServiceProvider
8
{
9
    /**
10
     * Bootstrap the application services.
11
     *
12
     * @return void
13
     */
14 1
    public function boot()
15
    {
16
        //
17 1
    }
18
19
    /**
20
     * Register the application services.
21
     *
22
     * @return void
23
     */
24 1
    public function register()
25
    {
26 1
        if (! $this->app->configurationIsCached()) {
27 1
            $this->configureDefaults();
28 1
        }
29
30 1
        $this->configureForRequest($this->app['request']);
31 1
    }
32
33
    /**
34
     * Configure defaults.
35
     */
36 1
    protected function configureDefaults()
37
    {
38 1
        $this->appendAppDomainsConfig();
39
40 1
        $this->setMailConfig();
41 1
    }
42
43
    /**
44
     * Append "app.domains" config.
45
     */
46
    protected function appendAppDomainsConfig()
47
    {
48 1
        $this->app['config']['app.domains'] = array_map(function ($value) {
49 1
            if (is_string($domain = parse_url($value, PHP_URL_HOST))) {
50
                if (str_contains($domain, '.')) {
51
                    return $domain;
52
                }
53
            }
54 1
        }, $this->app['config']['holly.url']);
55 1
    }
56
57
    /**
58
     * Set "mail" config.
59
     */
60 1
    protected function setMailConfig()
61
    {
62 1
        if (str_contains($username = $this->app['config']['mail.username'], '@') &&
63 1
            $this->app['config']['mail.from.address'] == '[email protected]') {
64
            $this->app['config']['mail.from.address'] = $username;
65
        }
66
67 1
        if ($this->app['config']['mail.from.name'] == 'Example') {
68 1
            $this->app['config']['mail.from.name'] = $this->app['config']['app.name'];
69 1
        }
70 1
    }
71
72
    /**
73
     * Configure app for the request.
74
     *
75
     * @param  \Illuminate\Http\Request  $request
76
     */
77 1
    protected function configureForRequest($request)
78
    {
79 1
        $domain = $request->getHost();
80 1
        $identifier = array_search($domain, $this->app['config']['app.domains']);
81
82
        // Configure the cookie domain
83 1
        if (! is_null($identifier) && $this->app['config']->has('holly.cookie_domain.'.$identifier)) {
84
            $this->app['config']['session.domain'] = $this->app['config']['holly.cookie_domain.'.$identifier];
85
        }
86
87
        // Configure the auth defaults
88 1
        if (! is_null($identifier) && is_array($auth = $this->app['config']['holly.auth.'.$identifier])) {
89
            $this->app['config']['auth.defaults'] = $auth;
90
        }
91 1
    }
92
}
93