Completed
Push — master ( ba992d...dc755b )
by Davide
07:03
created

LaravelEventsCalendarServiceProvider   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 0
loc 81
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B boot() 0 61 4
A register() 0 10 1
1
<?php
2
3
namespace DavideCasiraghi\LaravelEventsCalendar;
4
5
use Carbon\Carbon;
6
use Illuminate\Support\ServiceProvider;
7
8
class LaravelEventsCalendarServiceProvider extends ServiceProvider
9
{
10
    /**
11
     * Bootstrap the application services.
12
     */
13
    public function boot()
14
    {
15
        /*
16
         * Optional methods to load your package assets
17
         */
18
        // $this->loadTranslationsFrom(__DIR__.'/../resources/lang', 'laravel-events-calendar');
19
        // $this->loadViewsFrom(__DIR__.'/../resources/views', 'laravel-events-calendar');
20
        // $this->loadMigrationsFrom(__DIR__.'/../database/migrations');
21
        // $this->loadRoutesFrom(__DIR__.'/routes.php');
22
23
        if ($this->app->runningInConsole()) {
24
            $this->publishes([
25
                __DIR__.'/../config/config.php' => config_path('laravel-events-calendar.php'),
26
            ], 'config');
27
28
            // Publishing the views.
29
            /*$this->publishes([
30
                __DIR__.'/../resources/views' => resource_path('views/vendor/laravel-events-calendar'),
31
            ], 'views');*/
32
33
            // Publishing assets.
34
            /*$this->publishes([
35
                __DIR__.'/../resources/assets' => public_path('vendor/laravel-events-calendar'),
36
            ], 'assets');*/
37
38
            // Publishing the translation files.
39
            /*$this->publishes([
40
                __DIR__.'/../resources/lang' => resource_path('lang/vendor/laravel-events-calendar'),
41
            ], 'lang');*/
42
43
            // Registering package commands.
44
            // $this->commands([]);
45
            
46
            
47
            /* - Migrations - 
48
               create a migration instance for each .php.stub file eg. 
49
               create_continents_table.php.stub --->  2019_04_28_190434761474_create_continents_table.php
50
            */
51
                $migrations = [
52
                     'CreateQuotesTable' => 'create_continents_table',
53
                     'CreateCountriesTable' => 'create_countries_table',
54
                     'CreateEventHasOrganizersTable' => 'create_event_has_organizers_table',
55
                     'CreateEventHasTeachersTable' => 'create_event_has_teachers_table',
56
                     'CreateEventsTable' => 'create_events_table',
57
                     'CreateOrganizersTable' => 'create_organizers_table',
58
                     'CreateEventCategoriesTable' => 'event_categories_table',
59
                     'CreateEventRepetitionsTable' => 'event_repetitions_table',
60
                     'CreateEventVenuesTable' => 'event_venues',
61
                 ];
62
            
63
                foreach ($migrations as $migrationFunctionName => $migrationFileName) {
64
                    if (! class_exists($migrationFunctionName)) {
65
                        $this->publishes([
66
                            __DIR__.'/../database/migrations/'.$migrationFileName.'.php.stub' => database_path('migrations/'.Carbon::now()->format('Y_m_d_Hmsu').'_'.$migrationFileName.'.php'),
0 ignored issues
show
Bug introduced by
The method format does only exist in Carbon\CarbonInterface, but not in Carbon\Traits\Creator.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
67
                        ], 'migrations');
68
                    }
69
                }
70
            
71
            
72
        }
73
    }
74
75
    /**
76
     * Register the application services.
77
     */
78
    public function register()
79
    {
80
        // Automatically apply the package configuration
81
        $this->mergeConfigFrom(__DIR__.'/../config/config.php', 'laravel-events-calendar');
82
83
        // Register the main class to use with the facade
84
        $this->app->singleton('laravel-events-calendar', function () {
85
            return new LaravelEventsCalendar;
86
        });
87
    }
88
}
89