Passed
Push — master ( bb924a...090072 )
by Vasyl
01:56
created

ServiceProvider   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 29
c 0
b 0
f 0
dl 0
loc 78
rs 10
wmc 9

7 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 7 1
A registerMiddleware() 0 4 1
A checkMakeDir() 0 6 2
A register() 0 11 1
A publishConfig() 0 6 1
A publishMigrations() 0 8 2
A publishSeeder() 0 6 1
1
<?php
2
3
namespace Fomvasss\UrlAliases;
4
5
use Fomvasss\UrlAliases\Middleware\UrlAliasMiddleware;
6
use Illuminate\Contracts\Http\Kernel;
7
8
class ServiceProvider extends \Illuminate\Support\ServiceProvider
9
{
10
    protected $defer = false;
11
12
    /**
13
     * Bootstrap the application services.
14
     *
15
     * @return void
16
     */
17
    public function boot()
18
    {
19
        $this->publishConfig();
20
21
        $this->publishMigrations();
22
23
        $this->publishSeeder();
24
        
25
//        $this->registerMiddleware(UrlAliasMiddleware::class);
26
    }
27
28
    /**
29
     * Register the application services.
30
     *
31
     * @return void
32
     */
33
    public function register()
34
    {
35
        $this->mergeConfigFrom(__DIR__.'/../config/url-aliases.php', 'url-aliases');
36
        $this->mergeConfigFrom(__DIR__.'/../config/url-aliases-laravellocalization.php', 'url-aliases-laravellocalization');
37
38
        $this->app->singleton(UrlAliasLocalization::class, function () {
39
            return new UrlAliasLocalization($this->app);
40
        });
41
42
        $this->app->singleton(UrlAlias::class, function () {
43
            return new UrlAlias($this->app);
44
        });
45
    }
46
47
    protected function publishConfig()
48
    {
49
        $this->publishes([
50
            __DIR__ . '/../config/url-aliases.php' => config_path('url-aliases.php'),
0 ignored issues
show
Bug introduced by
The function config_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

50
            __DIR__ . '/../config/url-aliases.php' => /** @scrutinizer ignore-call */ config_path('url-aliases.php'),
Loading history...
51
            __DIR__ . '/../config/url-aliases-laravellocalization.php' => config_path('url-aliases-laravellocalization.php'),
52
        ], 'url-aliases-config');
53
    }
54
55
    protected function publishSeeder()
56
    {
57
        $seedPath = __DIR__ . '/../database/seeds/UrlAliasesTableSeeder.php.stub';
58
        $this->publishes([
59
            $seedPath => database_path('seeds/UrlAliasesTableSeeder.php')
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

59
            $seedPath => /** @scrutinizer ignore-call */ database_path('seeds/UrlAliasesTableSeeder.php')
Loading history...
60
        ], 'url-aliases-seeder');
61
    }
62
63
    protected function publishMigrations()
64
    {
65
        if (! class_exists('CreateUrlAliasesTable')) {
66
            $timestamp = date('Y_m_d_His', time());
67
68
            $migrationPath = __DIR__.'/../database/migrations/create_url_aliases_table.php';
69
                $this->publishes([$migrationPath => database_path('/migrations/' . $timestamp . '_create_url_aliases_table.php'),
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

69
                $this->publishes([$migrationPath => /** @scrutinizer ignore-call */ database_path('/migrations/' . $timestamp . '_create_url_aliases_table.php'),
Loading history...
70
            ], 'url-aliases-migrations');
71
        }
72
    }
73
74
    protected function registerMiddleware($middleware)
75
    {
76
        $kernel = $this->app[Kernel::class];
77
        $kernel->pushMiddleware($middleware);
78
    }
79
80
    protected function checkMakeDir(string $path)
81
    {
82
        if (!is_dir($path)) {
83
            mkdir($path, 0755, true);
84
        }
85
        return $path;
86
    }
87
}
88