Passed
Push — master ( ca7d80...7a0d15 )
by Philippe
03:38
created

AssetLibraryServiceProvider   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 65
Duplicated Lines 16.92 %

Coupling/Cohesion

Components 2
Dependencies 3

Test Coverage

Coverage 96.43%

Importance

Changes 5
Bugs 2 Features 0
Metric Value
wmc 7
c 5
b 2
f 0
lcom 2
cbo 3
dl 11
loc 65
ccs 27
cts 28
cp 0.9643
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 10 1
A register() 0 6 1
A registerModelBindings() 0 4 1
A registerAssetLibrary() 0 6 1
A publishMigrations() 11 15 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Thinktomorrow\AssetLibrary;
4
5
use Illuminate\Support\ServiceProvider;
6
use Thinktomorrow\AssetLibrary\Models\Asset;
7
use Illuminate\Database\Eloquent\Factory as EloquentFactory;
8
9
class AssetLibraryServiceProvider extends ServiceProvider
10
{
11
    /**
12
     * Indicates if loading of the provider is deferred.
13
     *
14
     * @var bool
15
     */
16
    protected $defer = false;
17
18
    /**
19
     * Perform post-registration booting of services.
20
     *
21
     * @return void
22
     */
23 64
    public function boot()
24
    {
25 64
        $this->publishes([
26 64
            __DIR__.'/../config/assetlibrary.php' => config_path('assetlibrary.php'),
27 64
        ], 'config');
28
29 64
        $this->publishMigrations();
30
31 64
        $this->registerModelBindings();
32 64
    }
33
34
    /**
35
     * Register any package services.
36
     *
37
     * @return void
38
     */
39 64
    public function register()
40
    {
41 64
        $this->mergeConfigFrom(__DIR__.'/../config/assetlibrary.php', 'assetlibrary');
42
43 64
        $this->registerAssetLibrary();
44 64
    }
45
46 64
    protected function registerModelBindings()
47
    {
48
        //TODO implement this
49 64
    }
50
51
    private function registerAssetLibrary()
52
    {
53 64
        $this->app->singleton('asset', function ($app) {
54
            return new Asset($app);
55 64
        });
56 64
    }
57
58 64
    public function publishMigrations(): void
59
    {
60 64 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...
61 1
            $this->publishes([
62 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 121 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...
63 1
                        time()).'_create_asset_table.php'),
64 1
            ], 'migrations');
65
        }
66
67 64 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...
68 1
            $this->publishes([
69 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...
70 1
            ], 'migrations');
71
        }
72 64
    }
73
}
74