AppServiceProvider::getSelectedTheme()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 7
nc 4
nop 0
1
<?php
2
3
namespace App\Providers;
4
5
use App\Models\Theme;
6
use App\Services\AboutMeService;
7
use Illuminate\Support\ServiceProvider;
8
use App\Interfaces\AboutMeServiceInterface;
9
10
class AppServiceProvider extends ServiceProvider
11
{
12
    /**
13
     * Bootstrap any application services.
14
     *
15
     * @return void
16
     */
17
    public function boot()
18
    {
19
        //
20
    }
21
22
    public function register()
23
    {
24
        $this->app->bind(AboutMeServiceInterface::class, AboutMeService::class);
25
        $this->app->singleton('theme', function () {
26
            return $this->getSelectedTheme();
27
        });
28
    }
29
30
    private function getSelectedTheme()
31
    {
32
        $theme = Theme::where('selected', true)->first();
33
34
        if ($theme === null) {
35
            $theme = Theme::first();
36
        }
37
38
        if ($theme === null) {
39
            $theme = factory(Theme::class)->create();
40
        }
41
42
        return $theme;
43
    }
44
}
45