GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

MiniCmsServiceProvider::getMigrationFileName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
namespace Chadanuk\MiniCms;
4
5
use Illuminate\Support\Collection;
6
use Illuminate\Filesystem\Filesystem;
7
use Illuminate\Support\Facades\Event;
8
use Illuminate\Support\ServiceProvider;
9
use Chadanuk\MiniCms\Events\PageCreating;
10
use Illuminate\View\Compilers\BladeCompiler;
11
use Chadanuk\MiniCms\Listeners\CheckPageSlug;
12
13
class MiniCmsServiceProvider extends ServiceProvider
14
{
15
    /**
16
     * Bootstrap the application services.
17
     */
18
    public function boot(Filesystem $filesystem)
19
    {
20
        /*
21
         * Optional methods to load your package assets
22
         */
23
        // $this->loadTranslationsFrom(__DIR__.'/../resources/lang', 'mini-cms');
24
        // $this->loadViewsFrom(__DIR__.'/../resources/views', 'mini-cms');
25
26
        $this->publishes([
27
            __DIR__ . '/../database/migrations/create_blocks_table.php' =>
28
            $this->getMigrationFilename($filesystem, 'create_blocks_table.php'),
29
            __DIR__ . '/../database/migrations/create_block_contents_table.php' =>
30
            $this->getMigrationFilename($filesystem, 'create_block_contents_table.php'),
31
            __DIR__ . '/../database/migrations/create_pages_table.php' =>
32
            $this->getMigrationFilename($filesystem, 'create_pages_table.php'),
33
            __DIR__ . '/../database/migrations/create_pages_blocks_table.php' =>
34
            $this->getMigrationFilename($filesystem, 'create_pages_blocks_table.php'),
35
        ], 'migrations');
36
37
        // $this->loadRoutesFrom(__DIR__.'/routes.php');
38
39
40
        $this->publishes([
41
            __DIR__ . '/../config/config.php' => config_path('mini-cms.php'),
42
        ], 'config');
43
44
        // Publishing the views.
45
        $this->publishes([
46
            __DIR__ . '/../resources/views' => resource_path('views/vendor/mini-cms'),
47
        ], 'mini-cms');
48
49
50
        // Publishing assets.
51
        /*$this->publishes([
52
            __DIR__.'/../resources/assets' => public_path('vendor/mini-cms'),
53
        ], 'assets');*/
54
55
56
        // Publishing the translation files.
57
        /*$this->publishes([
58
            __DIR__.'/../resources/lang' => resource_path('lang/vendor/mini-cms'),
59
        ], 'lang');*/
60
        if ($this->app->runningInConsole()) {
61
            // Registering package commands.
62
            // $this->commands([]);
63
        }
64
        $this->loadViewsFrom(__DIR__ . '/../resources/views', 'mini-cms');
65
    }
66
67
    /**
68
     * Register the application services.
69
     */
70
    public function register()
71
    {
72
        // Automatically apply the package configuration
73
        $this->mergeConfigFrom(__DIR__ . '/../config/config.php', 'mini-cms');
74
75
        // Register the main class to use with the facade
76
        $this->app->singleton('mini-cms', function () {
77
            return new MiniCms;
78
        });
79
80
        Event::listen(PageCreating::class, CheckPageSlug::class);
81
        $this->registerBladeExtensions();
82
    }
83
84
    public function registerBladeExtensions()
85
    {
86
        $this->app->afterResolving('blade.compiler', function (BladeCompiler $bladeCompiler) {
87
            $bladeCompiler->directive('minicms', function ($arguments) {
88
                list($type, $label) = explode(',', $arguments . ',');
89
90
                return "<?php \MiniCms::renderBlock($type, $label) ?>";
91
            });
92
        });
93
    }
94
95
    /**
96
     * Returns existing migration file if found, else uses the current timestamp.
97
     *
98
     * @param Filesystem $filesystem
99
     * @return string
100
     */
101
    protected function getMigrationFileName(Filesystem $filesystem, $filename): string
102
    {
103
        $timestamp = date('Y_m_d_His');
104
        return Collection::make($this->app->databasePath() . DIRECTORY_SEPARATOR . 'migrations' . DIRECTORY_SEPARATOR)
105
            ->flatMap(function ($path) use ($filesystem, $filename) {
106
                return $filesystem->glob($path . $filename);
107
            })->push($this->app->databasePath() . "/migrations/{$timestamp}_{$filename}")
108
            ->first();
109
    }
110
}
111