Issues (210)

src/Providers/AdmineticServiceProvider.php (11 issues)

1
<?php
2
3
namespace Pratiksh\Adminetic\Providers;
4
5
use App\Models\User;
0 ignored issues
show
The type App\Models\User 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...
6
use Illuminate\Routing\Router;
7
use Illuminate\Support\Facades\Auth;
8
use Illuminate\Support\Facades\Blade;
9
use Illuminate\Support\Facades\Gate;
10
use Illuminate\Support\Facades\Route;
11
use Illuminate\Support\ServiceProvider;
12
use Livewire\Livewire;
13
use Pratiksh\Adminetic\Console\Commands\AdmineticDummyCommand;
14
use Pratiksh\Adminetic\Console\Commands\AdmineticResetCommand;
15
use Pratiksh\Adminetic\Console\Commands\ClearActivityLogCommand;
16
use Pratiksh\Adminetic\Console\Commands\InstallAdmineticCommand;
17
use Pratiksh\Adminetic\Console\Commands\MakeAPIForAllModelCommand;
18
use Pratiksh\Adminetic\Console\Commands\MakeAPIResourceCommand;
19
use Pratiksh\Adminetic\Console\Commands\MakeCRUDGeneratorCommand;
20
use Pratiksh\Adminetic\Console\Commands\MakePermissionCommand;
21
use Pratiksh\Adminetic\Console\Commands\MakeRepositoryPatternCommand;
22
use Pratiksh\Adminetic\Console\Commands\MakeServiceCommand;
23
use Pratiksh\Adminetic\Console\Commands\MakeSuperUserCommand;
24
use Pratiksh\Adminetic\Console\Commands\MakeTraitCommand;
25
use Pratiksh\Adminetic\Contracts\PermissionRepositoryInterface;
26
use Pratiksh\Adminetic\Contracts\PreferenceRepositoryInterface;
27
use Pratiksh\Adminetic\Contracts\ProfileRepositoryInterface;
28
use Pratiksh\Adminetic\Contracts\RoleRepositoryInterface;
29
use Pratiksh\Adminetic\Contracts\SettingRepositoryInterface;
30
use Pratiksh\Adminetic\Contracts\UserRepositoryInterface;
31
use Pratiksh\Adminetic\Http\Livewire\Admin\Activity\ActivityTable;
32
use Pratiksh\Adminetic\Http\Livewire\Admin\Profile\EditAccount;
33
use Pratiksh\Adminetic\Http\Livewire\Admin\Profile\EditProfile;
34
use Pratiksh\Adminetic\Http\Livewire\Admin\Role\AclPanel;
35
use Pratiksh\Adminetic\Http\Livewire\Admin\Role\Bread;
36
use Pratiksh\Adminetic\Http\Livewire\Admin\User\UserTable;
37
use Pratiksh\Adminetic\Http\Livewire\Admin\UserPreferences;
0 ignored issues
show
The type Pratiksh\Adminetic\Http\...e\Admin\UserPreferences 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...
38
use Pratiksh\Adminetic\Http\Middleware\BouncerMiddleware;
39
use Pratiksh\Adminetic\Http\Middleware\RoleMiddleware;
40
use Pratiksh\Adminetic\Mixins\AdmineticAuthMixins;
41
use Pratiksh\Adminetic\Models\Admin\Preference;
42
use Pratiksh\Adminetic\Models\Permission;
0 ignored issues
show
The type Pratiksh\Adminetic\Models\Permission 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...
43
use Pratiksh\Adminetic\Models\Role;
0 ignored issues
show
The type Pratiksh\Adminetic\Models\Role 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...
44
use Pratiksh\Adminetic\Models\Setting;
0 ignored issues
show
The type Pratiksh\Adminetic\Models\Setting 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...
45
use Pratiksh\Adminetic\Policies\PermissionPolicy;
46
use Pratiksh\Adminetic\Policies\PreferencePolicy;
47
use Pratiksh\Adminetic\Policies\RolePolicy;
48
use Pratiksh\Adminetic\Policies\SettingPolicy;
49
use Pratiksh\Adminetic\Policies\UserPolicy;
50
use Pratiksh\Adminetic\Repositories\PermissionRepository;
51
use Pratiksh\Adminetic\Repositories\PreferenceRepository;
52
use Pratiksh\Adminetic\Repositories\ProfileRepository;
53
use Pratiksh\Adminetic\Repositories\RoleRepository;
54
use Pratiksh\Adminetic\Repositories\SettingRepository;
55
use Pratiksh\Adminetic\Repositories\UserRepository;
56
use Pratiksh\Adminetic\Services\Adminetic;
57
use Pratiksh\Adminetic\View\Components\Action;
58
use Pratiksh\Adminetic\View\Components\Card;
59
use Pratiksh\Adminetic\View\Components\CreatePage;
60
use Pratiksh\Adminetic\View\Components\EditAddButton;
61
use Pratiksh\Adminetic\View\Components\EditPage;
62
use Pratiksh\Adminetic\View\Components\IndexPage;
63
use Pratiksh\Adminetic\View\Components\ShowPage;
64
use Pratiksh\Adminetic\View\Components\Sidebar;
65
66
class AdmineticServiceProvider extends ServiceProvider
67
{
68
    // Register Policies
69
    protected $policies = [
70
        User::class => UserPolicy::class,
71
        Permission::class => PermissionPolicy::class,
72
        Role::class => RolePolicy::class,
73
        Setting::class => SettingPolicy::class,
74
        Preference::class => PreferencePolicy::class,
75
    ];
76
    /**
77
     * The path to the "home" route for your application.
78
     *
79
     * This is used by Laravel authentication to redirect users after login.
80
     *
81
     * @var string
82
     */
83
    public const HOME = '/admin/dashboard';
84
85
    /**
86
     * Bootstrap services.
87
     *
88
     * @return void
89
     */
90
    public function boot()
91
    {
92
        // Publish Ressource
93
        if ($this->app->runningInConsole()) {
94
            $this->publishResource();
95
        }
96
        // Register Resources
97
        $this->registerResource();
98
        // Register Middleware
99
        $this->registerMiddleware();
100
        // Register Directives
101
        $this->directives();
102
        // Register Policies
103
        $this->registerPolicies();
104
        // Register View Components
105
        $this->registerComponents();
106
        // Register Livewire Component
107
        $this->registerLivewire();
108
    }
109
110
    /**
111
     * Register services.
112
     *
113
     * @return void
114
     */
115
    public function register()
116
    {
117
        // Register Package Commands
118
        $this->registerCommands();
119
        /* Repository Interface Binding */
120
        $this->repos();
121
        // Register Mixins
122
        Route::mixin(new AdmineticAuthMixins());
123
        // Register Package Service Providers
124
        $this->app->register(AdmineticEventServiceProvider::class);
125
        // Register Facades
126
        $this->getFacades();
127
    }
128
129
    /**
130
     * Publish Package Resource.
131
     *
132
     * @return void
133
     */
134
    protected function publishResource()
135
    {
136
        // Publish Config File
137
        $this->publishes([
138
            __DIR__.'/../../config/adminetic.php' => config_path('adminetic.php'),
139
        ], 'adminetic-config');
140
        // Publish View Files
141
        $this->publishes([
142
            __DIR__.'/../../resources/views' => resource_path('views/vendor/adminetic'),
143
        ], 'adminetic-views');
144
        // Publish Migration Files
145
        $this->publishes([
146
            __DIR__.'/../../database/migrations' => database_path('migrations'),
147
        ], 'adminetic-migrations');
148
        // Publish Database Seeds
149
        $this->publishes([
150
            __DIR__.'/../../database/seeders' => database_path('seeders'),
151
        ], 'adminetic-seeders');
152
        $this->publishes([
153
            __DIR__.'/../../payload/assets' => public_path('adminetic/assets'),
154
        ], 'adminetic-assets-files');
155
        // Publish Static Files
156
        $this->publishes([
157
            __DIR__.'/../../payload/static' => public_path('adminetic/static'),
158
        ], 'adminetic-static-files');
159
    }
160
161
    /**
162
     * Register Package Resource.
163
     *
164
     * @return void
165
     */
166
    protected function registerResource()
167
    {
168
        $this->loadMigrationsFrom(__DIR__.'/../../database/migrations'); // Loading Migration Files
169
        $this->loadViewsFrom(__DIR__.'/../../resources/views', 'adminetic'); // Loading Views Files
170
        $this->registerRoutes();
171
    }
172
173
    /**
174
     * Register Routes.
175
     *
176
     * @return void
177
     */
178
    protected function registerRoutes()
179
    {
180
        Route::group($this->routeConfiguration(), function () {
0 ignored issues
show
Are you sure the usage of $this->routeConfiguration() targeting Pratiksh\Adminetic\Provi...r::routeConfiguration() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
$this->routeConfiguration() of type void is incompatible with the type Closure|array|string expected by parameter $attributes of Illuminate\Support\Facades\Route::group(). ( Ignorable by Annotation )

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

180
        Route::group(/** @scrutinizer ignore-type */ $this->routeConfiguration(), function () {
Loading history...
181
            $this->loadRoutesFrom(__DIR__.'/../../routes/web.php');
182
        });
183
    }
184
185
    /**
186
     * Register Route Configuration.
187
     *
188
     * @return void
189
     */
190
    protected function routeConfiguration()
191
    {
192
        return [
0 ignored issues
show
Bug Best Practice introduced by
The expression return array('prefix' =>... array('web', 'auth'))) returns the type array which is incompatible with the documented return type void.
Loading history...
193
            'prefix' => config('adminetic.prefix', 'admin'),
194
            'middleware' => config('adminetic.middleware', ['web', 'auth']),
195
        ];
196
    }
197
198
    /**
199
     * Register Package Command.
200
     *
201
     * @return void
202
     */
203
    protected function registerCommands()
204
    {
205
        $this->commands([
206
            MakeCRUDGeneratorCommand::class,
207
            MakePermissionCommand::class,
208
            MakeRepositoryPatternCommand::class,
209
            MakeServiceCommand::class,
210
            MakeSuperUserCommand::class,
211
            MakeTraitCommand::class,
212
            InstallAdmineticCommand::class,
213
            AdmineticDummyCommand::class,
214
            AdmineticResetCommand::class,
215
            MakeAPIResourceCommand::class,
216
            MakeAPIForAllModelCommand::class,
217
            ClearActivityLogCommand::class,
218
        ]);
219
    }
220
221
    /**
222
     * Blade Directives.
223
     *
224
     * @return void
225
     */
226
    protected function directives()
227
    {
228
        Blade::if('hasRole', function ($roles) {
229
            $hasAccess = false;
230
            $roles_array = explode('|', $roles);
231
            foreach ($roles_array as $role) {
232
                $hasAccess = $hasAccess || Auth::user()->hasRole($role) || Auth::user()->isSuperAdmin();
0 ignored issues
show
The method hasRole() does not exist on Illuminate\Contracts\Auth\Authenticatable. It seems like you code against a sub-type of Illuminate\Contracts\Auth\Authenticatable such as Illuminate\Foundation\Auth\User. ( Ignorable by Annotation )

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

232
                $hasAccess = $hasAccess || Auth::user()->/** @scrutinizer ignore-call */ hasRole($role) || Auth::user()->isSuperAdmin();
Loading history...
The method isSuperAdmin() does not exist on Illuminate\Contracts\Auth\Authenticatable. It seems like you code against a sub-type of Illuminate\Contracts\Auth\Authenticatable such as Illuminate\Foundation\Auth\User. ( Ignorable by Annotation )

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

232
                $hasAccess = $hasAccess || Auth::user()->hasRole($role) || Auth::user()->/** @scrutinizer ignore-call */ isSuperAdmin();
Loading history...
233
            }
234
235
            return $hasAccess;
236
        });
237
        Blade::if('preference', function ($preference_name, $default_value) {
238
            return preference($preference_name, $default_value);
239
        });
240
        Blade::directive('setting', function ($setting_name) {
241
            return "<?php echo setting($setting_name) ?>";
242
        });
243
    }
244
245
    /**
246
     * Repository Binding.
247
     *
248
     * @return void
249
     */
250
    protected function repos()
251
    {
252
        $this->app->bind(UserRepositoryInterface::class, UserRepository::class);
253
        $this->app->bind(ProfileRepositoryInterface::class, ProfileRepository::class);
254
        $this->app->bind(RoleRepositoryInterface::class, RoleRepository::class);
255
        $this->app->bind(PermissionRepositoryInterface::class, PermissionRepository::class);
256
        $this->app->bind(SettingRepositoryInterface::class, SettingRepository::class);
257
        $this->app->bind(PreferenceRepositoryInterface::class, PreferenceRepository::class);
258
    }
259
260
    /**
261
     * Register Middlewares.
262
     *
263
     * @return void
264
     */
265
    protected function registerMiddleware()
266
    {
267
        $router = $this->app->make(Router::class);
268
        $router->aliasMiddleware('role', RoleMiddleware::class);
269
        $router->aliasMiddleware('bouncer', BouncerMiddleware::class);
270
    }
271
272
    /**
273
     * Register View Components.
274
     *
275
     * @return void
276
     */
277
    protected function registerComponents()
278
    {
279
        $this->loadViewComponentsAs('adminetic', [
280
            Sidebar::class,
281
            Action::class,
282
            Card::class,
283
            CreatePage::class,
284
            EditPage::class,
285
            IndexPage::class,
286
            ShowPage::class,
287
            EditAddButton::class,
288
        ]);
289
    }
290
291
    /**
292
     * Register Policies.
293
     *
294
     * @return void
295
     */
296
    protected function registerPolicies()
297
    {
298
        foreach ($this->policies as $key => $value) {
299
            Gate::policy($key, $value);
300
        }
301
    }
302
303
    /**
304
     * Register Livewire Components.
305
     */
306
    protected function registerLivewire()
307
    {
308
        Livewire::component('admin.user.user-table', UserTable::class);
309
        Livewire::component('admin.user.user-preferences', UserPreferences::class);
310
        Livewire::component('admin.profile.edit-account', EditAccount::class);
311
        Livewire::component('admin.profile.edit-profile', EditProfile::class);
312
        Livewire::component('admin.activity.activity-table', ActivityTable::class);
313
        Livewire::component('admin.role.acl-panel', AclPanel::class);
314
        Livewire::component('admin.role.bread', Bread::class);
315
    }
316
317
    /**
318
     * Facades.
319
     */
320
    protected function getFacades()
321
    {
322
        $this->app->bind('adminetic', function ($app) {
0 ignored issues
show
The parameter $app 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

322
        $this->app->bind('adminetic', function (/** @scrutinizer ignore-unused */ $app) {

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...
323
            return new Adminetic();
324
        });
325
    }
326
}
327