Passed
Push — master ( 765c1f...eb8479 )
by Philippe
02:18
created

AssetLibraryServiceProvider::setupRoutes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Thinktomorrow\AssetLibrary;
4
5
use Illuminate\Database\Eloquent\Factory as EloquentFactory;
6
use Illuminate\Routing\Router;
7
use Illuminate\Support\ServiceProvider;
8
use Thinktomorrow\AssetLibrary\Models\Asset;
9
10
class AssetLibraryServiceProvider extends ServiceProvider
11
{
12
    /**
13
     * Indicates if loading of the provider is deferred.
14
     *
15
     * @var bool
16
     */
17
    protected $defer = false;
18
19
    /**
20
     * Perform post-registration booting of services.
21
     *
22
     * @return void
23
     */
24 60
    public function boot()
25
    {
26 60
        $this->publishes([
27 60
            __DIR__.'/../config/assetlibrary.php' => config_path('assetlibrary.php'),
28 60
        ], 'config');
29
30 60
        $this->loadRoutesFrom(__DIR__.'/Http/routes.php');
31
32 60
        $this->publishMigrations();
33
34 60
        $this->registerModelBindings();
35 60
        $this->registerEloquentFactoriesFrom(__DIR__.'/../database/factories');
36 60
    }
37
38
    /**
39
     * Register factories.
40
     *
41
     * @param  string  $path
42
     * @return void
43
     */
44 60
    protected function registerEloquentFactoriesFrom($path)
45
    {
46 60
        $this->app->make(EloquentFactory::class)->load($path);
47 60
    }
48
49
    /**
50
     * Register any package services.
51
     *
52
     * @return void
53
     */
54 60
    public function register()
55
    {
56 60
        $this->mergeConfigFrom(__DIR__.'/../config/assetlibrary.php', 'assetlibrary');
57
58 60
        $this->registerAssetLibrary();
59 60
    }
60
61 60
    protected function registerModelBindings()
62
    {
63
        //TODO implement this
64 60
    }
65
66
    /**
67
     *
68
     */
69
    private function registerAssetLibrary()
70
    {
71 60
        $this->app->singleton('asset', function ($app) {
72
            return new Asset($app);
73 60
        });
74 60
    }
75
76
    /**
77
     *
78
     */
79 60
    public function publishMigrations(): void
80
    {
81 60 View Code Duplication
        if (!class_exists('CreateAssetTable')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
82 1
            $this->publishes([
83 1
                __DIR__ . '/../database/migrations/create_asset_table.php' => database_path('migrations/' . date('Y_m_d_His',
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 125 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
84 1
                        time()) . '_create_asset_table.php'),
85 1
            ], 'migrations');
86
87
        }
88
89 60 View Code Duplication
        if (! class_exists('CreateMediaTable')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
90 1
            $this->publishes([
91 1
                __DIR__.'/../../../spatie/laravel-medialibrary/database/migrations/create_media_table.php.stub' => database_path('migrations/'.date('Y_m_d_His', time()).'_create_media_table.php'),
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 196 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
92 1
            ], 'migrations');
93
        }
94 60
    }
95
}
96