Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Completed
Pull Request — master (#224)
by Owen
10:24
created

CrudServiceProvider   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 152
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 152
rs 10
c 0
b 0
f 0
wmc 7
lcom 2
cbo 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 48 3
A register() 0 19 1
B resource() 0 46 1
A shouldAutoPublishPublic() 0 10 2
1
<?php
2
3
namespace Backpack\CRUD;
4
5
use Illuminate\Support\ServiceProvider;
6
use Route;
7
8
class CrudServiceProvider extends ServiceProvider
9
{
10
    /**
11
     * Indicates if loading of the provider is deferred.
12
     *
13
     * @var bool
14
     */
15
    protected $defer = false;
16
17
    /**
18
     * Perform post-registration booting of services.
19
     *
20
     * @return void
21
     */
22
    public function boot()
23
    {
24
        // LOAD THE VIEWS
25
26
        // - first the published/overwritten views (in case they have any changes)
27
        $this->loadViewsFrom(resource_path('views/vendor/backpack/crud'), 'crud');
28
        // - then the stock views that come with the package, in case a published view might be missing
29
        $this->loadViewsFrom(realpath(__DIR__.'/resources/views'), 'crud');
30
31
        $this->loadTranslationsFrom(realpath(__DIR__.'/resources/lang'), 'backpack');
32
33
34
        // PUBLISH FILES
35
36
        // publish lang files
37
        $this->publishes([__DIR__.'/resources/lang' => resource_path('lang/vendor/backpack')], 'lang');
38
39
        // publish views
40
        $this->publishes([__DIR__.'/resources/views' => resource_path('views/vendor/backpack/crud')], 'views');
41
42
        // publish config file
43
        $this->publishes([__DIR__.'/config' => config_path()], 'config');
44
45
        // publish public Backpack CRUD assets
46
        $this->publishes([__DIR__.'/public' => public_path('vendor/backpack')], 'public');
47
48
        // publish custom files for elFinder
49
        $this->publishes([
50
            __DIR__.'/config/elfinder.php'      => config_path('elfinder.php'),
51
            __DIR__.'/resources/views-elfinder' => resource_path('views/vendor/elfinder'),
52
        ], 'elfinder');
53
54
        // AUTO PUBLISH
55
        if (\App::environment('local')) {
56
            if ($this->shouldAutoPublishPublic()) {
57
                \Artisan::call('vendor:publish', [
58
                    '--provider' => 'Backpack\CRUD\CrudServiceProvider',
59
                    '--tag' => 'public',
60
                ]);
61
            }
62
        }
63
64
65
        // use the vendor configuration file as fallback
66
        $this->mergeConfigFrom(
67
            __DIR__.'/config/backpack/crud.php', 'backpack.crud'
68
        );
69
    }
70
71
    /**
72
     * Register any package services.
73
     *
74
     * @return void
75
     */
76
    public function register()
77
    {
78
        $this->app->bind('CRUD', function ($app) {
79
            return new CRUD($app);
80
        });
81
82
        // register its dependencies
83
        $this->app->register(\Backpack\Base\BaseServiceProvider::class);
84
        $this->app->register(\Collective\Html\HtmlServiceProvider::class);
85
        $this->app->register(\Barryvdh\Elfinder\ElfinderServiceProvider::class);
86
        $this->app->register(\Intervention\Image\ImageServiceProvider::class);
87
88
        // register their aliases
89
        $loader = \Illuminate\Foundation\AliasLoader::getInstance();
90
        $loader->alias('CRUD', \Backpack\CRUD\CrudServiceProvider::class);
0 ignored issues
show
Coding Style introduced by
As per coding style, self should be used for accessing local static members.

This check looks for accesses to local static members using the fully qualified name instead of self::.

<?php

class Certificate {
    const TRIPLEDES_CBC = 'ASDFGHJKL';

    private $key;

    public function __construct()
    {
        $this->key = Certificate::TRIPLEDES_CBC;
    }
}

While this is perfectly valid, the fully qualified name of Certificate::TRIPLEDES_CBC could just as well be replaced by self::TRIPLEDES_CBC. Referencing local members with self:: assured the access will still work when the class is renamed, makes it perfectly clear that the member is in fact local and will usually be shorter.

Loading history...
91
        $loader->alias('Form', \Collective\Html\FormFacade::class);
92
        $loader->alias('Html', \Collective\Html\HtmlFacade::class);
93
        $loader->alias('Image', \Intervention\Image\Facades\Image::class);
94
    }
95
96
    public static function resource($name, $controller, array $options = [])
97
    {
98
        // CRUD routes
99
        Route::post($name.'/search', [
100
            'as' => 'crud.'.$name.'.search',
101
            'uses' => $controller.'@search',
102
          ]);
103
        Route::get($name.'/reorder', [
104
            'as' => 'crud.'.$name.'.reorder',
105
            'uses' => $controller.'@reorder',
106
          ]);
107
        Route::post($name.'/reorder', [
108
            'as' => 'crud.'.$name.'.save.reorder',
109
            'uses' => $controller.'@saveReorder',
110
          ]);
111
        Route::get($name.'/{id}/details', [
112
            'as' => 'crud.'.$name.'.showDetailsRow',
113
            'uses' => $controller.'@showDetailsRow',
114
          ]);
115
        Route::get($name.'/{id}/translate/{lang}', [
116
            'as' => 'crud.'.$name.'.translateItem',
117
            'uses' => $controller.'@translateItem',
118
          ]);
119
        Route::get($name.'/{id}/revisions', [
120
            'as' => 'crud.'.$name.'.listRevisions',
121
            'uses' => $controller.'@listRevisions',
122
          ]);
123
        Route::post($name.'/{id}/revisions/{revisionId}/restore', [
124
            'as' => 'crud.'.$name.'.restoreRevision',
125
            'uses' => $controller.'@restoreRevision',
126
          ]);
127
128
        $options_with_default_route_names = array_merge([
129
            'names' => [
130
                'index'     => 'crud.'.$name.'.index',
131
                'create'    => 'crud.'.$name.'.create',
132
                'store'     => 'crud.'.$name.'.store',
133
                'edit'      => 'crud.'.$name.'.edit',
134
                'update'    => 'crud.'.$name.'.update',
135
                'show'      => 'crud.'.$name.'.show',
136
                'destroy'   => 'crud.'.$name.'.destroy',
137
                ],
138
            ], $options);
139
140
        Route::resource($name, $controller, $options_with_default_route_names);
141
    }
142
143
    /**
144
     * Checks to see if we should automatically publish
145
     * vendor files from the public tag.
146
     *
147
     * @return bool
148
     */
149
    private function shouldAutoPublishPublic()
150
    {
151
        $crudPubPath = public_path('vendor/backpack/crud');
152
153
        if (! is_dir($crudPubPath)) {
0 ignored issues
show
Unused Code introduced by
This if statement, and the following return statement can be replaced with return !is_dir($crudPubPath);.
Loading history...
154
            return true;
155
        }
156
157
        return false;
158
    }
159
}
160