Completed
Push — version-4 ( 5bb021 )
by
unknown
08:16
created

NotifynderServiceProvider::migration()   F

Complexity

Conditions 10
Paths 512

Size

Total Lines 30
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 6
Bugs 1 Features 1
Metric Value
cc 10
eloc 19
c 6
b 1
f 1
nc 512
nop 0
dl 0
loc 30
rs 3.2187

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Fenos\Notifynder;
4
5
use Fenos\Notifynder\Collections\Config;
6
use Fenos\Notifynder\Contracts\ConfigContract;
7
use Fenos\Notifynder\Contracts\NotifynderContract;
8
use Fenos\Notifynder\Managers\NotifynderManager;
9
use Illuminate\Support\ServiceProvider;
10
11
class NotifynderServiceProvider extends ServiceProvider
12
{
13
    public function register()
14
    {
15
        $this->bindContracts();
16
        $this->bindConfig();
17
        $this->bindNotifynder();
18
    }
19
20
    public function boot()
21
    {
22
        $this->config();
23
        $this->migration();
24
    }
25
26
    /**
27
     * Bind contracts.
28
     */
29
    protected function bindContracts()
30
    {
31
        $this->app->bind(NotifynderContract::class, 'notifynder');
32
        $this->app->bind(ConfigContract::class, 'notifynder.config');
33
    }
34
35
    /**
36
     * Bind notifynder config.
37
     */
38
    protected function bindConfig()
39
    {
40
        $this->app->singleton('notifynder.config', function ($app) {
0 ignored issues
show
Unused Code introduced by
The parameter $app is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
41
            return new Config();
42
        });
43
    }
44
45
    /**
46
     * Bind notifynder manager.
47
     */
48
    protected function bindNotifynder()
49
    {
50
        $this->app->singleton('notifynder', function ($app) {
51
            return new NotifynderManager(
52
                $app['notifynder.category'],
0 ignored issues
show
Unused Code introduced by
The call to NotifynderManager::__construct() has too many arguments starting with $app['notifynder.category'].

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
53
                $app['notifynder.sender'],
54
                $app['notifynder.notification'],
55
                $app['notifynder.dispatcher'],
56
                $app['notifynder.group']
57
            );
58
        });
59
    }
60
61
    /**
62
     * Publish config file.
63
     */
64
    protected function config()
65
    {
66
        $this->publishes([
67
            __DIR__.'/../config/notifynder.php' => config_path('notifynder.php'),
68
        ]);
69
70
        $this->mergeConfigFrom(__DIR__.'/../config/notifynder.php', 'notifynder');
71
    }
72
73
    /**
74
     * Publish migration files.
75
     */
76
    protected function migration()
77
    {
78
        if (! class_exists('NotificationCategories')) {
79
            $this->publishMigration('2014_02_10_145728_notification_categories');
80
        }
81
        if (! class_exists('CreateNotificationGroupsTable')) {
82
            $this->publishMigration('2014_08_01_210813_create_notification_groups_table');
83
        }
84
        if (! class_exists('CreateNotificationCategoryNotificationGroupTable')) {
85
            $this->publishMigration('2014_08_01_211045_create_notification_category_notification_group_table');
86
        }
87
        if (! class_exists('CreateNotificationsTable')) {
88
            $this->publishMigration('2015_05_05_212549_create_notifications_table');
89
        }
90
        if (! class_exists('AddExpireTimeColumnToNotificationTable')) {
91
            $this->publishMigration('2015_06_06_211555_add_expire_time_column_to_notification_table');
92
        }
93
        if (! class_exists('ChangeTypeToExtraInNotificationsTable')) {
94
            $this->publishMigration('2015_06_06_211555_change_type_to_extra_in_notifications_table');
95
        }
96
        if (! class_exists('AlterCategoryNameToUnique')) {
97
            $this->publishMigration('2015_06_07_211555_alter_category_name_to_unique');
98
        }
99
        if (! class_exists('MakeNotificationUrlNullable')) {
100
            $this->publishMigration('2016_04_19_200827_make_notification_url_nullable');
101
        }
102
        if (! class_exists('AddStackIdToNotifications')) {
103
            $this->publishMigration('2016_05_19_144531_add_stack_id_to_notifications');
104
        }
105
    }
106
107
    /**
108
     * @param string $filename
109
     */
110
    protected function publishMigration($filename)
111
    {
112
        $extension = '.php';
113
        $filename = trim($filename, $extension).$extension;
114
        $stub = __DIR__.'/../migrations/'.$filename;
115
        $target = $this->migrationFilepath($filename);
116
        $this->publishes([$stub => $target], 'migrations');
117
    }
118
119
    /**
120
     * @param string $filename
121
     * @return string
122
     */
123
    protected function migrationFilepath($filename)
124
    {
125
        if (function_exists('database_path')) {
126
            return database_path('/migrations/'.$filename);
127
        } else {
128
            return base_path('/database/migrations/'.$filename);
129
        }
130
    }
131
}
132