AdminServiceProvider::routes()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 9
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 12
rs 9.9666
1
<?php
2
3
namespace App\Providers;
4
5
use App\Http\Terranet\Administrator\Dashboard\BlankPanel;
6
use App\Http\Terranet\Administrator\Dashboard\DatabasePanel;
7
use App\Http\Terranet\Administrator\Dashboard\MembersPanel;
8
use Illuminate\Support\ServiceProvider;
9
use Illuminate\Support\Str;
10
use Pingpong\Menus\Menu;
11
use Pingpong\Menus\MenuBuilder;
12
use Pingpong\Menus\MenuItem;
13
use Terranet\Administrator\Architect;
14
use Terranet\Administrator\Contracts\Module\Navigable;
15
use Terranet\Administrator\Dashboard\Manager;
16
use Terranet\Administrator\Dashboard\Row;
17
use Terranet\Options\Manager as OptionsManager;
0 ignored issues
show
Bug introduced by
The type Terranet\Options\Manager was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
18
19
class AdminServiceProvider extends ServiceProvider
20
{
21
    /**
22
     * Dashboard panels registration.
23
     *
24
     * @param  Manager  $dashboard
25
     * @return Manager
26
     */
27
    protected function dashboard(Manager $dashboard)
28
    {
29
        return $dashboard
30
            ->row(static function (Row $row) {
31
                $row->panel(new BlankPanel())->setWidth(12);
32
            })
33
            ->row(static function (Row $row) {
34
                $row->panel(new MembersPanel())->setWidth(6);
35
                $row->panel(new DatabasePanel())->setWidth(6);
36
            });
37
    }
38
39
    /**
40
     * @param  Menu  $navigation
41
     * @return Menu
42
     */
43
    protected function navigation(Menu $navigation)
44
    {
45
        $this->initSidebar($navigation)
46
            ->initToolbar($navigation);
47
48
        return $navigation;
49
    }
50
51
    /**
52
     * Register services.
53
     *
54
     * @return void
55
     */
56
    public function register()
57
    {
58
        $this->app->singleton('scaffold.dashboard', function () {
59
            return $this->dashboard(new Manager());
60
        });
61
62
        $this->app->singleton('scaffold.navigation', function ($app) {
63
            return $this->navigation(new Menu($app['view'], $app['config']));
64
        });
65
    }
66
67
    /**
68
     * Bootstrap any application services.
69
     *
70
     * @return void
71
     */
72
    public function boot()
73
    {
74
        $this->routes();
75
    }
76
77
    /**
78
     * Register AdminArchitect routes.
79
     */
80
    protected function routes()
81
    {
82
        Architect::routes()
83
            ->withAuthenticationRoutes()
84
            ->withTranslationRoutes()
85
            ->withMediaRoutes()
86
            ->withSettingRoutes()
87
            ->withExtraRoutes(function () {
88
                $path = 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

88
                $path = /** @scrutinizer ignore-call */ base_path('routes/admin.php');
Loading history...
89
90
                if (file_exists($path)) {
91
                    $this->loadRoutesFrom($path);
92
                }
93
            });
94
    }
95
96
    /**
97
     * @param  Menu  $navigation
98
     * @return AdminServiceProvider
99
     */
100
    protected function initSidebar(Menu $navigation): self
101
    {
102
        $navigation->create(Navigable::MENU_SIDEBAR, function (MenuBuilder $sidebar) {
103
            $this->withDashboard($sidebar);
104
105
            // Create "resources" group
106
            $sidebar->dropdown(trans('administrator::module.groups.resources'), static function (MenuItem $sub) {
0 ignored issues
show
Unused Code introduced by
The parameter $sub is not used and could be removed. ( Ignorable by Annotation )

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

106
            $sidebar->dropdown(trans('administrator::module.groups.resources'), static function (/** @scrutinizer ignore-unused */ MenuItem $sub) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Bug introduced by
The function trans 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

106
            $sidebar->dropdown(/** @scrutinizer ignore-call */ trans('administrator::module.groups.resources'), static function (MenuItem $sub) {
Loading history...
107
                // $sub->route();
108
            }, 2, ['id' => 'groups', 'icon' => 'fa fa-qrcode']);
109
        });
110
111
        return $this;
112
    }
113
114
    /**
115
     * @param  Menu  $navigation
116
     * @return AdminServiceProvider
117
     */
118
    protected function initToolbar(Menu $navigation): self
119
    {
120
        $navigation->create(Navigable::MENU_TOOLS, function (MenuBuilder $tools) {
121
            $this->withMedia($tools)
122
                ->withSettings($tools)
123
                ->withTranslations($tools);
124
125
            $tools->url(
126
                route('scaffold.logout'),
0 ignored issues
show
Bug introduced by
The function route 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

126
                /** @scrutinizer ignore-call */ 
127
                route('scaffold.logout'),
Loading history...
127
                trans('administrator::buttons.logout'),
0 ignored issues
show
Bug introduced by
The function trans 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

127
                /** @scrutinizer ignore-call */ 
128
                trans('administrator::buttons.logout'),
Loading history...
128
                100,
129
                ['icon' => 'fa fa-mail-forward']
130
            );
131
        });
132
133
        return $this;
134
    }
135
136
    /**
137
     * @param  MenuBuilder  $sidebar
138
     * @return $this
139
     */
140
    public function withDashboard(MenuBuilder $sidebar): self
141
    {
142
        $sidebar->route('scaffold.dashboard', trans('administrator::module.dashboard'), [], 1, [
0 ignored issues
show
Bug introduced by
The function trans 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

142
        $sidebar->route('scaffold.dashboard', /** @scrutinizer ignore-call */ trans('administrator::module.dashboard'), [], 1, [
Loading history...
143
            'id' => 'dashboard',
144
            'icon' => 'fa fa-home',
145
            'active' => Str::is(request()->route()->getName(), 'scaffold.dashboard'),
0 ignored issues
show
Bug introduced by
The function request 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

145
            'active' => Str::is(/** @scrutinizer ignore-call */ request()->route()->getName(), 'scaffold.dashboard'),
Loading history...
146
        ]);
147
148
        return $this;
149
    }
150
151
    /**
152
     * @param  MenuBuilder  $tools
153
     * @return $this
154
     */
155
    protected function withMedia(MenuBuilder $tools): self
156
    {
157
        if (config('administrator.file_manager.enabled')) {
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

157
        if (/** @scrutinizer ignore-call */ config('administrator.file_manager.enabled')) {
Loading history...
158
            $tools->url(
159
                route('scaffold.media'),
0 ignored issues
show
Bug introduced by
The function route 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

159
                /** @scrutinizer ignore-call */ 
160
                route('scaffold.media'),
Loading history...
160
                trans('administrator::buttons.media'),
0 ignored issues
show
Bug introduced by
The function trans 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

160
                /** @scrutinizer ignore-call */ 
161
                trans('administrator::buttons.media'),
Loading history...
161
                1,
162
                ['icon' => 'fa fa-file-text-o']
163
            );
164
        }
165
166
        return $this;
167
    }
168
169
    /**
170
     * @param  MenuBuilder  $tools
171
     * @return $this
172
     */
173
    protected function withSettings(MenuBuilder $tools): self
174
    {
175
        if (config('administrator.settings.enabled') && class_exists(OptionsManager::class, true)) {
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

175
        if (/** @scrutinizer ignore-call */ config('administrator.settings.enabled') && class_exists(OptionsManager::class, true)) {
Loading history...
176
            $tools->url(
177
                route('scaffold.settings.edit'),
0 ignored issues
show
Bug introduced by
The function route 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

177
                /** @scrutinizer ignore-call */ 
178
                route('scaffold.settings.edit'),
Loading history...
178
                trans('administrator::module.resources.settings'),
0 ignored issues
show
Bug introduced by
The function trans 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

178
                /** @scrutinizer ignore-call */ 
179
                trans('administrator::module.resources.settings'),
Loading history...
179
                2,
180
                ['icon' => 'fa fa-gears']
181
            );
182
        }
183
184
        return $this;
185
    }
186
187
    /**
188
     * @param  MenuBuilder  $tools
189
     * @return $this
190
     */
191
    protected function withTranslations(MenuBuilder $tools): self
192
    {
193
        if (config('administrator.translations.enabled')) {
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

193
        if (/** @scrutinizer ignore-call */ config('administrator.translations.enabled')) {
Loading history...
194
            $tools->url(
195
                route('scaffold.translations.index'),
0 ignored issues
show
Bug introduced by
The function route 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

195
                /** @scrutinizer ignore-call */ 
196
                route('scaffold.translations.index'),
Loading history...
196
                trans('administrator::buttons.translations'),
0 ignored issues
show
Bug introduced by
The function trans 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

196
                /** @scrutinizer ignore-call */ 
197
                trans('administrator::buttons.translations'),
Loading history...
197
                3,
198
                ['icon' => 'fa fa-globe']
199
            );
200
        }
201
202
        return $this;
203
    }
204
}
205