Passed
Push — master ( b51903...6b2d83 )
by Philippe
08:32
created

AssetLibraryServiceProvider   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 54
Duplicated Lines 22.22 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 80%

Importance

Changes 4
Bugs 2 Features 0
Metric Value
wmc 6
c 4
b 2
f 0
lcom 1
cbo 3
dl 12
loc 54
ccs 20
cts 25
cp 0.8
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 15 1
A publishMigrations() 12 15 3
A getConfig() 0 7 2

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
     * Register any package services.
20
     *
21
     * @return void
22
     */
23 65
    public function register()
24
    {
25 65
        $this->publishes([
26 65
            __DIR__.'/../config/assetlibrary.php' => config_path('assetlibrary.php'),
27 65
        ], 'config');
28
29 65
        $this->mergeConfigFrom(__DIR__.'/../config/assetlibrary.php', 'assetlibrary');
30
31 65
        $this->app->singleton('asset', function ($app) {
32
            return new Asset($app);
33 65
        });
34
35 65
        $this->publishMigrations();
36
37 65
    }
38
39 65
    public function publishMigrations(): void
40
    {
41 65 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...
42 1
            $this->publishes([
43 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...
44 1
                        time()).'_create_asset_table.php'),
45 1
            ], 'migrations');
46
        }
47
48 65 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...
49 1
            $this->publishes([
50 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...
51 1
            ], 'migrations');
52
        }
53 65
    }
54
55
    private function getConfig()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
56
    {
57
        if (file_exists(config_path('thinktomorrow/assetlibrary.php'))) {
58
            return require config_path('thinktomorrow/assetlibrary.php');
59
        }
60
        return require __DIR__.'/../config/assetlibrary.php';
61
    }
62
}
63