Passed
Branch feature/cropping (36fe5e)
by Philippe
02:13
created

AssetLibraryServiceProvider   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 92
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 96.97%

Importance

Changes 3
Bugs 2 Features 0
Metric Value
wmc 8
c 3
b 2
f 0
lcom 1
cbo 4
dl 0
loc 92
ccs 32
cts 33
cp 0.9697
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 13 1
A registerEloquentFactoriesFrom() 0 4 1
A setupRoutes() 0 6 1
A register() 0 6 1
A registerModelBindings() 0 4 1
A registerAssetLibrary() 0 6 1
A publishMigrations() 0 9 2
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 43
    public function boot()
25
    {
26 43
        $this->publishes([
27 43
            __DIR__.'/../config/thinktomorrow/assetlibrary.php' => config_path('assetlibrary.php'),
28 43
        ], 'config');
29
30 43
        $this->setupRoutes($this->app->router);
0 ignored issues
show
Bug introduced by
Accessing router on the interface Illuminate\Contracts\Foundation\Application suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
31
32 43
        $this->publishMigrations();
33
34 43
        $this->registerModelBindings();
35 43
        $this->registerEloquentFactoriesFrom(__DIR__.'/../database/factories');
36 43
    }
37
38
    /**
39
     * Register factories.
40
     *
41
     * @param  string  $path
42
     * @return void
43
     */
44 43
    protected function registerEloquentFactoriesFrom($path)
45
    {
46 43
        $this->app->make(EloquentFactory::class)->load($path);
47 43
    }
48
49
    /**
50
     * Define the routes for the application.
51
     *
52
     * @param  \Illuminate\Routing\Router  $router
53
     * @return void
54
     */
55
    public function setupRoutes(Router $router)
56
    {
57 43
        $router->group(['namespace' => 'Thinktomorrow\AssetLibrary\Http\Controllers'], function ($router) {
58 43
            require __DIR__.'/Http/routes.php';
59 43
        });
60 43
    }
61
62
    /**
63
     * Register any package services.
64
     *
65
     * @return void
66
     */
67 43
    public function register()
68
    {
69 43
        $this->mergeConfigFrom(__DIR__.'/../config/assetlibrary.php', 'assetlibrary');
70
71 43
        $this->registerAssetLibrary();
72 43
    }
73
74 43
    protected function registerModelBindings()
75
    {
76
        //TODO implement this
77 43
    }
78
79
    /**
80
     *
81
     */
82
    private function registerAssetLibrary()
83
    {
84 43
        $this->app->singleton('asset', function ($app) {
85
            return new Asset($app);
86 43
        });
87 43
    }
88
89
    /**
90
     *
91
     */
92 43
    public function publishMigrations(): void
93
    {
94 43
        if (!class_exists('CreateAssetTable')) {
95 1
            $this->publishes([
96 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...
97 1
                        time()) . '_create_asset_table.php'),
98 1
            ], 'migrations');
99
        }
100 43
    }
101
}
102