ServiceProvider::configureAuth()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 8
c 1
b 0
f 0
nc 4
nop 0
dl 0
loc 13
ccs 0
cts 7
cp 0
crap 12
rs 10
1
<?php
2
3
namespace Terranet\Administrator;
4
5
use Collective\Html\FormFacade;
6
use Collective\Html\HtmlFacade;
7
use Collective\Html\HtmlServiceProvider;
8
use Illuminate\Support\ServiceProvider as BaseServiceProvider;
9
use Pingpong\Menus\MenuFacade;
10
use Pingpong\Menus\MenusServiceProvider;
11
use App\Providers\AdminServiceProvider;
12
use Terranet\Administrator\Providers\ArtisanServiceProvider;
13
use Terranet\Administrator\Providers\ContainersServiceProvider;
14
use Terranet\Administrator\Providers\EventServiceProvider;
15
16
class ServiceProvider extends BaseServiceProvider
17
{
18
    public function boot()
19
    {
20
        $baseDir = realpath(__DIR__.'/../');
21
22
        // Publish & Load routes
23
        $this->publishes([
24
            "{$baseDir}/publishes/routes.php" => base_path('routes/admin.php'),
0 ignored issues
show
Bug introduced by
The function base_path was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

24
            "{$baseDir}/publishes/routes.php" => /** @scrutinizer ignore-call */ base_path('routes/admin.php'),
Loading history...
25
        ], 'routes');
26
27
        // Publish & Load configuration
28
        $this->publishes(["{$baseDir}/publishes/config.php" => config_path('administrator.php')], 'config');
0 ignored issues
show
Bug introduced by
The function config_path was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

28
        $this->publishes(["{$baseDir}/publishes/config.php" => /** @scrutinizer ignore-call */ config_path('administrator.php')], 'config');
Loading history...
29
        $this->mergeConfigFrom("{$baseDir}/publishes/config.php", 'administrator');
30
31
        // Publish Mix files
32
        $this->publishes(["{$baseDir}/publishes/mix" => base_path('adminarchitect-mix')], 'assets');
33
34
        // Publish & Load views, assets
35
        $this->publishes(["{$baseDir}/publishes/views" => base_path('resources/views/vendor/administrator')], 'views');
36
        $this->loadViewsFrom("{$baseDir}/publishes/views", 'administrator');
37
38
        // Publish & Load translations
39
        $this->publishes(
40
            ["{$baseDir}/publishes/translations" => base_path('resources/lang/vendor/administrator')],
41
            'translations'
42
        );
43
        $this->loadTranslationsFrom("{$baseDir}/publishes/translations", 'administrator');
44
45
        // Publish default Administrator Starter Kit: modules, dashboard panels, policies, etc...
46
        $this->publishes(
47
            ["{$baseDir}/publishes/Modules" => app_path('Http/Terranet/Administrator/Modules')],
0 ignored issues
show
Bug introduced by
The function app_path was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

47
            ["{$baseDir}/publishes/Modules" => /** @scrutinizer ignore-call */ app_path('Http/Terranet/Administrator/Modules')],
Loading history...
48
            'boilerplate'
49
        );
50
        $this->publishes(
51
            ["{$baseDir}/publishes/Dashboard" => app_path('Http/Terranet/Administrator/Dashboard')],
52
            'boilerplate'
53
        );
54
        $this->publishes(
55
            ["{$baseDir}/publishes/Providers" => app_path('Providers')],
56
            'boilerplate'
57
        );
58
59
        $this->configureAuth();
60
    }
61
62
    /**
63
     * Register the service provider.
64
     */
65
    public function register()
66
    {
67
        $dependencies = [];
68
69
        // Ensure the ServiceProvider has been published
70
        if (file_exists(app_path("Providers/AdminServiceProvider.php"))) {
0 ignored issues
show
Bug introduced by
The function app_path was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

70
        if (file_exists(/** @scrutinizer ignore-call */ app_path("Providers/AdminServiceProvider.php"))) {
Loading history...
71
            $dependencies[] = AdminServiceProvider::class;
72
        }
73
74
        $dependencies = array_merge($dependencies, [
75
            ArtisanServiceProvider::class,
76
            ContainersServiceProvider::class,
77
            EventServiceProvider::class,
78
            HtmlServiceProvider::class => [
79
                'Html' => HtmlFacade::class,
80
                'Form' => FormFacade::class,
81
            ],
82
            MenusServiceProvider::class => [
83
                'AdminNav' => MenuFacade::class,
84
            ],
85
        ]);
86
87
        array_walk($dependencies, function ($package, $provider) {
88
            if (\is_string($package) && is_numeric($provider)) {
89
                $provider = $package;
90
                $package = null;
91
            }
92
93
            if (!$this->app->getProvider($provider)) {
0 ignored issues
show
Bug introduced by
The method getProvider() does not exist on Illuminate\Contracts\Foundation\Application. Did you maybe mean getProviders()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

93
            if (!$this->app->/** @scrutinizer ignore-call */ getProvider($provider)) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
94
                $this->app->register($provider);
95
96
                if (\is_array($package)) {
97
                    foreach ($package as $alias => $facade) {
98
                        if (class_exists($alias)) {
99
                            continue;
100
                        }
101
102
                        class_alias($facade, $alias);
103
                    }
104
                }
105
            }
106
        });
107
    }
108
109
    protected function configureAuth()
110
    {
111
        if (!config()->has('auth.guards.admin')) {
0 ignored issues
show
Bug introduced by
The function config was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

111
        if (!/** @scrutinizer ignore-call */ config()->has('auth.guards.admin')) {
Loading history...
112
            config()->set('auth.guards.admin', [
113
                'driver' => 'session',
114
                'provider' => 'admins',
115
            ]);
116
        }
117
118
        if (!config()->has('auth.providers.admins')) {
119
            config()->set('auth.providers.admins', [
120
                'driver' => 'eloquent',
121
                'model' => config('administrator.auth.model'),
122
            ]);
123
        }
124
    }
125
}
126