ServiceProvider   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 93
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 9
eloc 23
dl 0
loc 93
ccs 29
cts 29
cp 1
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A publishMigrations() 0 9 2
A publishConfigs() 0 7 1
A boot() 0 8 1
A registerRouteBindings() 0 3 1
A register() 0 3 1
A registerBindings() 0 4 1
A __construct() 0 3 1
A registerMiddleware() 0 3 1
1
<?php
2
3
namespace Tofandel\Redirects;
4
5
use Illuminate\Contracts\Foundation\Application;
6
use Illuminate\Routing\Router;
7
use Illuminate\Support\Facades\File;
8
use Illuminate\Support\Facades\Route;
9
use Illuminate\Support\ServiceProvider as BaseServiceProvider;
10
use Tofandel\Redirects\Contracts\RedirectModelContract;
11
use Tofandel\Redirects\Middleware\RedirectRequests;
12
use Tofandel\Redirects\Models\Redirect;
13
14
class ServiceProvider extends BaseServiceProvider
15
{
16
    /**
17
     * @var Router
18
     */
19
    protected $router;
20
21
    /**
22
     * Create a new service provider instance.
23
     *
24
     * @param  Application  $app
25
     */
26 3
    public function __construct(Application $app)
27
    {
28 3
        parent::__construct($app);
29
    }
30
31
    /**
32
     * Bootstrap the application services.
33
     *
34
     * @param  Router  $router
35
     * @return void
36
     */
37 1
    public function boot(Router $router)
38
    {
39 1
        $this->router = $router;
40
41 1
        $this->publishConfigs();
42 1
        $this->publishMigrations();
43 1
        $this->registerMiddleware();
44 1
        $this->registerRouteBindings();
45
    }
46
47
    /**
48
     * Register the application services.
49
     *
50
     * @return void
51
     */
52 1
    public function register()
53
    {
54 1
        $this->registerBindings();
55
    }
56
57
    /**
58
     * @return void
59
     */
60 1
    protected function publishConfigs()
61
    {
62 1
        $this->mergeConfigFrom(realpath(__DIR__.'/../config/redirects.php'), 'redirects');
63
64 1
        $this->publishes([
65 1
            __DIR__.'/../config/redirects.php' => config_path('redirects.php'),
66 1
        ], 'config');
67
    }
68
69
    /**
70
     * @return void
71
     */
72 1
    protected function publishMigrations()
73
    {
74 1
        if (empty(File::glob(database_path('migrations/*_create_redirects_table.php')))) {
75 1
            $timestamp = date('Y_m_d_His', time());
76 1
            $migration = database_path("migrations/{$timestamp}_create_redirects_table.php");
77
78 1
            $this->publishes([
79 1
                __DIR__.'/../database/migrations/0000_00_00_000000_create_redirects_table.php' => $migration,
80 1
            ], 'migrations');
81
        }
82
    }
83
84
    /**
85
     * @return void
86
     */
87 1
    protected function registerMiddleware()
88
    {
89 1
        $this->router->aliasMiddleware('redirect.requests', RedirectRequests::class);
90
    }
91
92
    /**
93
     * @return void
94
     */
95 1
    protected function registerRouteBindings()
96
    {
97 1
        Route::model('redirect', RedirectModelContract::class);
98
    }
99
100
    /**
101
     * @return void
102
     */
103 1
    protected function registerBindings()
104
    {
105 1
        $this->app->bind(RedirectModelContract::class, $this->config['redirects']['redirect_model'] ?? Redirect::class);
0 ignored issues
show
Bug Best Practice introduced by
The property config does not exist on Tofandel\Redirects\ServiceProvider. Did you maybe forget to declare it?
Loading history...
106 1
        $this->app->alias(RedirectModelContract::class, 'redirect.model');
107
    }
108
}
109