Passed
Push — main ( 52a9ba...b89683 )
by PRATIK
04:37 queued 14s
created

CategoryServiceProvider::boot()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
nc 2
nop 0
dl 0
loc 12
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace Adminetic\Website\Provider;
4
5
use Livewire\Livewire;
0 ignored issues
show
Bug introduced by
The type Livewire\Livewire 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\Support\Facades\Gate;
7
use Illuminate\Support\Facades\Route;
8
use Illuminate\Support\ServiceProvider;
9
use Adminetic\Website\Models\Admin\Category;
10
use Adminetic\Website\Policies\CategoryPolicy;
11
use Adminetic\Website\Repository\CategoryRepository;
12
use Adminetic\Website\Contracts\CategoryRepositoryInterface;
13
use Adminetic\Website\Console\AdmineticCategoryInstallCommand;
0 ignored issues
show
Bug introduced by
The type Adminetic\Website\Consol...cCategoryInstallCommand 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...
14
use Adminetic\Website\Http\Livewire\Admin\Category\QuickCategory;
15
use Adminetic\Website\Http\Livewire\Admin\Category\ReorderParentCategory;
16
use Adminetic\Website\Http\Livewire\Admin\Category\ReorderChildrenCategory;
17
18
19
class CategoryServiceProvider extends ServiceProvider
20
{
21
    // Register Policies
22
    protected $policies = [
23
        Category::class => CategoryPolicy::class,
24
    ];
25
26
    /**
27
     * Bootstrap services.
28
     *
29
     * @return void
30
     */
31
    public function boot()
32
    {
33
        // Publish Ressource
34
        if ($this->app->runningInConsole()) {
35
            $this->publishResource();
36
        }
37
        // Register Resources
38
        $this->registerResource();
39
        // Register Policies
40
        $this->registerPolicies();
41
        // Register View Components
42
        $this->registerLivewireComponents();
43
    }
44
45
    /**
46
     * Register services.
47
     *
48
     * @return void
49
     */
50
    public function register()
51
    {
52
        $this->registerCommands();
53
        /* Repository Interface Binding */
54
        $this->repos();
55
    }
56
57
    /**
58
     * Publish Package Resource.
59
     *
60
     *@return void
61
     */
62
    protected function publishResource()
63
    {
64
        // Publish Config File
65
        $this->publishes([
66
            __DIR__ . '/../../config/category.php' => config_path('category.php'),
67
        ], 'category-config');
68
        // Publish View Files
69
        $this->publishes([
70
            __DIR__ . '/../../resources/views' => resource_path('views/vendor/adminetic/plugin/category'),
71
        ], 'category-views');
72
        // Publish Migration Files
73
        $this->publishes([
74
            __DIR__ . '/../../database/migrations' => database_path('migrations'),
75
        ], 'category-migrations');
76
    }
77
78
    /**
79
     * Register Package Resource.
80
     *
81
     *@return void
82
     */
83
    protected function registerResource()
84
    {
85
        $this->loadMigrationsFrom(__DIR__ . '/../../database/migrations'); // Loading Migration Files
86
        $this->loadViewsFrom(__DIR__ . '/../../resources/views', 'category'); // Loading Views Files
87
        $this->registerRoutes();
88
    }
89
90
    /**
91
     * Register Package Command.
92
     *
93
     *@return void
94
     */
95
    protected function registerCommands()
96
    {
97
        $this->commands([
98
            AdmineticCategoryInstallCommand::class,
99
        ]);
100
    }
101
102
    /**
103
     * Register Routes.
104
     *
105
     * @return void
106
     */
107
    protected function registerRoutes()
108
    {
109
        Route::group($this->routeConfiguration(), function () {
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->routeConfiguration() targeting Adminetic\Website\Provid...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...
Bug introduced by
$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

109
        Route::group(/** @scrutinizer ignore-type */ $this->routeConfiguration(), function () {
Loading history...
110
            $this->loadRoutesFrom(__DIR__ . '/../../routes/web.php');
111
        });
112
    }
113
114
    /**
115
     * Register Route Configuration.
116
     *
117
     * @return void
118
     */
119
    protected function routeConfiguration()
120
    {
121
        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...
122
            'prefix' => config('adminetic.prefix', 'admin'),
123
            'middleware' => config('adminetic.middleware', ['web', 'auth']),
124
        ];
125
    }
126
127
    /**
128
     * Register Components.
129
     *
130
     *@return void
131
     */
132
    protected function registerLivewireComponents()
133
    {
134
        Livewire::component('admin.category.quick-category', QuickCategory::class);
135
        Livewire::component('admin.category.reorder-children-category', ReorderChildrenCategory::class);
136
        Livewire::component('admin.category.reorder-parent-category', ReorderParentCategory::class);
137
    }
138
139
    /**
140
     * Repository Binding.
141
     *
142
     * @return void
143
     */
144
    protected function repos()
145
    {
146
        $this->app->bind(CategoryRepositoryInterface::class, CategoryRepository::class);
147
    }
148
149
    /**
150
     * Register Policies.
151
     *
152
     *@return void
153
     */
154
    protected function registerPolicies()
155
    {
156
        foreach ($this->policies as $key => $value) {
157
            Gate::policy($key, $value);
158
        }
159
    }
160
}
161