Completed
Push — master ( 7927db...22ae38 )
by Emmanuel
24s queued 10s
created

LaravelTicketsServiceProvider::boot()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 56

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 56
rs 8.9599
c 0
b 0
f 0
cc 2
nc 2
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace RexlManu\LaravelTickets;
4
5
use Illuminate\Support\ServiceProvider;
6
use RexlManu\LaravelTickets\Commands\AutoCloseCommand;
7
use RexlManu\LaravelTickets\Controllers\TicketController;
8
use Illuminate\Routing\Router;
9
use Illuminate\Support\Facades\Route;
10
11
class LaravelTicketsServiceProvider extends ServiceProvider
12
{
13
    /**
14
     * Bootstrap the application services.
15
     */
16
    public function boot()
17
    {
18
        /*
19
         * Optional methods to load your package assets
20
         */
21
//        $this->loadTranslationsFrom(__DIR__ . '/../resources/lang', 'laravel-tickets');
22
        $this->loadViewsFrom(__DIR__ . '/../resources/views', 'laravel-tickets');
23
        $this->loadMigrationsFrom(__DIR__ . '/../database/migrations');
24
25
        if ($this->app->runningInConsole()) {
26
            $this->publishes([
27
                __DIR__ . '/../config/config.php' => config_path('laravel-tickets.php'),
28
            ], 'config');
29
30
            // Publishing the views.
31
            $this->publishes([
32
                __DIR__ . '/../resources/views' => resource_path('views/vendor/laravel-tickets'),
33
            ], 'views');
34
35
            $this->publishes([
36
                __DIR__ . '/../database/migrations' => database_path('migrations'),
37
            ], 'migrations');
38
39
            // Publishing assets.
40
            /*$this->publishes([
41
                __DIR__.'/../resources/assets' => public_path('vendor/laravel-tickets'),
42
            ], 'assets');*/
43
44
            // Publishing the translation files.
45
//            $this->publishes([
46
//                __DIR__ . '/../resources/lang' => resource_path('lang/vendor/laravel-tickets'),
47
//            ], 'lang');
48
49
            // Registering package commands.
50
            $this->commands([ AutoCloseCommand::class ]);
51
        }
52
        
53
        // Macro routing improved
54
        Router::macro('ticketSystem', function () {
55
            Route::middleware(config('laravel-tickets.guard'))->name('laravel-tickets.')->group(function () {
56
                Route::prefix('/tickets')->group(function () {
57
                    Route::get('/', [ TicketController::class, 'index' ])->name('tickets.index');
58
                    Route::post('/', [ TicketController::class, 'store' ])->name('tickets.store');
59
                    Route::get('/create', [ TicketController::class, 'create' ])->name('tickets.create');
60
                    Route::prefix('{ticket}')->group(function () {
61
                        Route::get('/', [ TicketController::class, 'show' ])->name('tickets.show');
62
                        Route::post('/', [ TicketController::class, 'close' ])->name('tickets.close');
63
                        Route::post('/message', [ TicketController::class, 'message' ])->name('tickets.message');
64
                        Route::prefix('{ticketUpload}')->group(function () {
65
                            Route::get('/download', [ TicketController::class, 'download' ])->name('tickets.download');
66
                        });
67
                    });
68
                });
69
            });
70
        });
71
    }
72
73
    /**
74
     * Register the application services.
75
     */
76
    public function register()
77
    {
78
        // Automatically apply the package configuration
79
        $this->mergeConfigFrom(__DIR__ . '/../config/config.php', 'laravel-tickets');
80
81
        // Register the main class to use with the facade
82
        $this->app->singleton('laravel-tickets', function () {
83
            return new LaravelTickets;
84
        });
85
    }
86
}
87