LaravelBlockerServiceProvider   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 112
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 45
dl 0
loc 112
rs 10
c 0
b 0
f 0
wmc 9

5 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 5 1
A packageRegistration() 0 7 1
A publishFiles() 0 23 1
A register() 0 9 1
A loadSeedsFrom() 0 22 5
1
<?php
2
3
namespace jeremykenedy\LaravelBlocker;
4
5
use Illuminate\Routing\Router;
6
use Illuminate\Support\ServiceProvider;
7
use jeremykenedy\LaravelBlocker\App\Http\Middleware\LaravelBlocker;
8
use jeremykenedy\LaravelBlocker\Database\Seeds\DefaultBlockedItemsTableSeeder;
9
use jeremykenedy\LaravelBlocker\Database\Seeds\DefaultBlockedTypeTableSeeder;
10
11
class LaravelBlockerServiceProvider extends ServiceProvider
12
{
13
    private $_packageTag = 'laravelblocker';
14
15
    /**
16
     * Indicates if loading of the provider is deferred.
17
     *
18
     * @var bool
19
     */
20
    protected $defer = false;
21
22
    /**
23
     * Bootstrap the application services.
24
     *
25
     * @return void
26
     */
27
    public function boot(Router $router)
28
    {
29
        $router->middlewareGroup('checkblocked', [LaravelBlocker::class]);
30
        $this->loadRoutesFrom(__DIR__.'/routes/web.php');
31
        $this->loadTranslationsFrom(__DIR__.'/resources/lang/', $this->_packageTag);
32
    }
33
34
    /**
35
     * Register the application services.
36
     *
37
     * @return void
38
     */
39
    public function register()
40
    {
41
        $this->packageRegistration();
42
        $this->loadRoutesFrom(__DIR__.'/routes/web.php');
43
        $this->loadViewsFrom(__DIR__.'/resources/views/', $this->_packageTag);
44
        $this->mergeConfigFrom(__DIR__.'/config/'.$this->_packageTag.'.php', $this->_packageTag);
45
        $this->loadMigrationsFrom(__DIR__.'/database/migrations');
46
        $this->loadSeedsFrom();
47
        $this->publishFiles();
48
    }
49
50
    /**
51
     * Package Registration.
52
     *
53
     * @return void
54
     */
55
    private function packageRegistration()
56
    {
57
        $this->app->make('jeremykenedy\LaravelBlocker\App\Http\Controllers\LaravelBlockerController');
58
        $this->app->singleton(jeremykenedy\LaravelBlocker\App\Http\Controllers\LaravelBlockerController::class, function () {
0 ignored issues
show
Bug introduced by
The type jeremykenedy\LaravelBloc...aravelBlockerController was not found. Did you mean jeremykenedy\LaravelBloc...aravelBlockerController? If so, make sure to prefix the type with \.
Loading history...
59
            return new App\Http\Controllers\LaravelBlockerController();
60
        });
61
        $this->app->alias(LaravelBlockerController::class, $this->_packageTag);
0 ignored issues
show
Bug introduced by
The type jeremykenedy\LaravelBloc...aravelBlockerController 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...
62
    }
63
64
    /**
65
     * Loads a seeds.
66
     *
67
     * @return void
68
     */
69
    private function loadSeedsFrom()
70
    {
71
        if (config('laravelblocker.seedDefaultBlockedTypes')) {
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

71
        if (/** @scrutinizer ignore-call */ config('laravelblocker.seedDefaultBlockedTypes')) {
Loading history...
72
            $this->app['seed.handler']->register(
73
                DefaultBlockedTypeTableSeeder::class
74
            );
75
        }
76
        if (config('laravelblocker.seedDefaultBlockedItems')) {
77
            $this->app['seed.handler']->register(
78
                DefaultBlockedItemsTableSeeder::class
79
            );
80
        }
81
82
        if (config('laravelblocker.useSeededBlockedTypes')) {
83
            $this->app['seed.handler']->register(
84
                \Database\Seeds\BlockedTypeTableSeeder::class
85
            );
86
        }
87
88
        if (config('laravelblocker.useSeededBlockedItems')) {
89
            $this->app['seed.handler']->register(
90
                \Database\Seeds\BlockedItemsTableSeeder::class
91
            );
92
        }
93
    }
94
95
    /**
96
     * Publish files for Laravel Blocker.
97
     *
98
     * @return void
99
     */
100
    private function publishFiles()
101
    {
102
        $publishTag = $this->_packageTag;
103
104
        $this->publishes([
105
            __DIR__.'/config/'.$this->_packageTag.'.php' => base_path('config/'.$this->_packageTag.'.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

105
            __DIR__.'/config/'.$this->_packageTag.'.php' => /** @scrutinizer ignore-call */ base_path('config/'.$this->_packageTag.'.php'),
Loading history...
106
        ], $publishTag.'-config');
107
108
        $this->publishes([
109
            __DIR__.'/resources/views' => base_path('resources/views/vendor/'),
110
        ], $publishTag.'-views');
111
112
        $this->publishes([
113
            __DIR__.'/resources/lang' => base_path('resources/lang/vendor/'.$this->_packageTag),
114
        ], $publishTag.'-lang');
115
116
        $this->publishes([
117
            __DIR__.'/database/migrations' => database_path('migrations'),
0 ignored issues
show
Bug introduced by
The function database_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

117
            __DIR__.'/database/migrations' => /** @scrutinizer ignore-call */ database_path('migrations'),
Loading history...
118
        ], $publishTag.'-migrations');
119
120
        $this->publishes([
121
            __DIR__.'/database/seeds/publish' => database_path('seeds'),
122
        ], $publishTag.'-seeds');
123
    }
124
}
125