Passed
Push — master ( 3e5b57...979fc2 )
by Hergen
05:00
created

getMigrationFileName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 9
rs 10
1
<?php
2
3
namespace werk365\JwtAuthRoles;
4
5
use Illuminate\Filesystem\Filesystem;
6
use Illuminate\Support\Collection;
7
use Illuminate\Support\ServiceProvider;
8
9
class JwtAuthRolesServiceProvider extends ServiceProvider
10
{
11
    public function boot(Filesystem $filesystem)
12
    {
13
        // $this->loadTranslationsFrom(__DIR__.'/../resources/lang', 'werk365');
14
        // $this->loadViewsFrom(__DIR__.'/../resources/views', 'werk365');
15
        // $this->loadMigrationsFrom(__DIR__.'/../database/migrations');
16
        // $this->loadRoutesFrom(__DIR__.'/routes.php');
17
18
        // Publishing is only necessary when using the CLI.
19
        if ($this->app->runningInConsole()) {
20
            $this->bootForConsole();
21
        }
22
23
        if (function_exists('config_path')) { // function not available and 'publish' not relevant in Lumen
24
            $this->publishes([
25
                __DIR__ . '/../config/jwtauthroles.php' => config_path('jwtauthroles.php'),
26
            ], 'config');
27
28
            $this->publishes([
29
                __DIR__.'/../database/migrations/create_jwtauth_tables.php.stub' => $this->getMigrationFileName($filesystem),
30
            ], 'migrations');
31
        }
32
    }
33
34
    /**
35
     * Register any package services.
36
     *
37
     * @return void
38
     */
39
    public function register()
40
    {
41
        $this->mergeConfigFrom(__DIR__ . '/../config/jwtauthroles.php', 'jwtauthroles');
42
43
        // Register the service the package provides.
44
        $this->app->singleton('JwtAuthRoles', function ($app) {
0 ignored issues
show
Unused Code introduced by
The parameter $app is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

44
        $this->app->singleton('JwtAuthRoles', function (/** @scrutinizer ignore-unused */ $app) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $app is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

44
        $this->app->singleton('JwtAuthRoles', function (/** @scrutinizer ignore-unused */ $app) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
45
            return new JwtAuthRoles;
46
        });
47
    }
48
49
    /**
50
     * Get the services provided by the provider.
51
     *
52
     * @return array
53
     */
54
    public function provides()
55
    {
56
        return ['JwtAuthRoles'];
57
    }
58
59
    /**
60
     * Console-specific booting.
61
     *
62
     * @return void
63
     */
64
    protected function bootForConsole()
65
    {
66
        // Publishing the configuration file.
67
        $this->publishes([
68
            __DIR__ . '/../config/jwtauthroles.php' => config_path('jwtauthroles.php'),
69
        ], 'jwtauthroles.config');
70
71
        // Publishing the views.
72
        /*$this->publishes([
73
            __DIR__.'/../resources/views' => base_path('resources/views/vendor/werk365'),
74
        ], 'jwtAuthRoles.views');*/
75
76
        // Publishing assets.
77
        /*$this->publishes([
78
            __DIR__.'/../resources/assets' => public_path('vendor/werk365'),
79
        ], 'jwtAuthRoles.views');*/
80
81
        // Publishing the translation files.
82
        /*$this->publishes([
83
            __DIR__.'/../resources/lang' => resource_path('lang/vendor/werk365'),
84
        ], 'jwtAuthRoles.views');*/
85
86
        // Registering package commands.
87
        // $this->commands([]);
88
    }
89
90
    /**
91
     * Returns existing migration file if found, else uses the current timestamp.
92
     *
93
     * @param Filesystem $filesystem
94
     * @return string
95
     */
96
    protected function getMigrationFileName(Filesystem $filesystem): string
97
    {
98
        $timestamp = date('Y_m_d_His');
99
100
        return Collection::make($this->app->databasePath().DIRECTORY_SEPARATOR.'migrations'.DIRECTORY_SEPARATOR)
101
            ->flatMap(function ($path) use ($filesystem) {
102
                return $filesystem->glob($path.'*_create_jwtauth_tables.php');
103
            })->push($this->app->databasePath()."/migrations/{$timestamp}_create_jwtauth_tables.php")
104
            ->first();
105
    }
106
}
107