ManagerServiceProvider::boot()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 4
ccs 0
cts 4
cp 0
crap 2
rs 10
1
<?php
2
3
namespace CodexShaper\DBM;
4
5
use CodexShaper\DBM\Commands\DatabaseAdmin;
6
use CodexShaper\DBM\Commands\DatabaseBackup;
7
use CodexShaper\DBM\Commands\DatabaseRestore;
8
use CodexShaper\DBM\Commands\DatabaseSeed;
9
use CodexShaper\DBM\Commands\InstallDatabaseManager;
10
use CodexShaper\DBM\MongoDB\Passport\AuthCode;
11
use CodexShaper\DBM\MongoDB\Passport\Bridge\RefreshToken;
12
use CodexShaper\DBM\MongoDB\Passport\Bridge\RefreshTokenRepository;
13
use CodexShaper\DBM\MongoDB\Passport\Client;
14
use CodexShaper\DBM\MongoDB\Passport\PersonalAccessClient;
15
use CodexShaper\DBM\MongoDB\Passport\Token;
16
use CodexShaper\Dumper\Contracts\Dumper;
17
use CodexShaper\Dumper\Drivers\MongoDumper;
18
use CodexShaper\Dumper\Drivers\MysqlDumper;
19
use CodexShaper\Dumper\Drivers\PgsqlDumper;
20
use CodexShaper\Dumper\Drivers\SqliteDumper;
21
use Illuminate\Support\ServiceProvider;
22
23
class ManagerServiceProvider extends ServiceProvider
24
{
25
    /**
26
     * Boot the service provider.
27
     *
28
     * @return void
29
     */
30
    public function boot()
31
    {
32
        $this->loadMigrationsFrom(__DIR__.'/../database/migrations');
0 ignored issues
show
Bug introduced by
The method loadMigrationsFrom() does not exist on CodexShaper\DBM\ManagerServiceProvider. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

32
        $this->/** @scrutinizer ignore-call */ 
33
               loadMigrationsFrom(__DIR__.'/../database/migrations');

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
33
        $this->loadViewsFrom(__DIR__.'/../resources/views', 'dbm');
0 ignored issues
show
Bug introduced by
The method loadViewsFrom() does not exist on CodexShaper\DBM\ManagerServiceProvider. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

33
        $this->/** @scrutinizer ignore-call */ 
34
               loadViewsFrom(__DIR__.'/../resources/views', 'dbm');

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
34
    }
35
36
    /**
37
     * Register the service provider.
38
     *
39
     * @return void
40
     */
41
    public function register()
42
    {
43
        $database = $this->app->config['database'];
0 ignored issues
show
Bug introduced by
The property config does not seem to exist on Tests\Laravel\App.
Loading history...
44
        // Bind Dumper to backup and and restore
45
        $this->app->bind(Dumper::class, function ($app) use ($database) {
0 ignored issues
show
Unused Code introduced by
The parameter $app is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

45
        $this->app->bind(Dumper::class, function (/** @scrutinizer ignore-unused */ $app) use ($database) {

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

Loading history...
Bug introduced by
The method bind() does not exist on Tests\Laravel\App. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

45
        $this->app->/** @scrutinizer ignore-call */ 
46
                    bind(Dumper::class, function ($app) use ($database) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
46
            $connection = $database['default'];
47
            $options = [
48
                'host' => $database['connections'][$connection]['host'] ?? '',
49
                'port' => $database['connections'][$connection]['port'] ?? 3306,
50
                'dbName' => $database['connections'][$connection]['database'] ?? '',
51
                'username' => $database['connections'][$connection]['username'] ?? 'root',
52
                'password' => $database['connections'][$connection]['password'] ?? '',
53
            ];
54
            switch ($connection) {
55
                case 'mysql':
56
                    return new MysqlDumper($options);
57
                    break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
58
                case 'sqlite':
59
                    return new SqliteDumper($options);
60
                    break;
61
                case 'pgsql':
62
                    return new PgsqlDumper($options);
63
                    break;
64
                case 'mongodb':
65
                    return new MongoDumper($options);
66
                    break;
67
            }
68
        });
69
        // Register aliases for mongoDB passport
70
        if ($database['default'] == 'mongodb') {
71
            if (class_exists('Illuminate\Foundation\AliasLoader')) {
72
                $loader = \Illuminate\Foundation\AliasLoader::getInstance();
73
                $loader->alias('Laravel\Passport\AuthCode', AuthCode::class);
74
                $loader->alias('Laravel\Passport\Client', Client::class);
75
                $loader->alias('Laravel\Passport\Bridge\RefreshTokenRepository', RefreshTokenRepository::class);
76
                $loader->alias('Laravel\Passport\Bridge\RefreshToken', RefreshToken::class);
77
                $loader->alias('Laravel\Passport\PersonalAccessClient', PersonalAccessClient::class);
78
                $loader->alias('Laravel\Passport\Token', Token::class);
79
            } else {
80
                class_alias('Laravel\Passport\AuthCode', AuthCode::class);
81
                class_alias('Laravel\Passport\Client', Client::class);
82
                class_alias('Laravel\Passport\Bridge\RefreshTokenRepository', RefreshTokenRepository::class);
83
                class_alias('Laravel\Passport\Bridge\RefreshToken', RefreshToken::class);
84
                class_alias('Laravel\Passport\PersonalAccessClient', PersonalAccessClient::class);
85
                class_alias('Laravel\Passport\Token', Token::class);
86
            }
87
        }
88
89
        $this->mergeConfigFrom(
0 ignored issues
show
Bug introduced by
The method mergeConfigFrom() does not exist on CodexShaper\DBM\ManagerServiceProvider. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

89
        $this->/** @scrutinizer ignore-call */ 
90
               mergeConfigFrom(

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
90
            __DIR__.'/../config/dbm.php', 'config'
91
        );
92
        $this->loadHelpers();
93
        $this->registerPublish();
94
        $this->registerCommands();
95
    }
96
97
    /**
98
     * Include helper files.
99
     *
100
     * @return void
101
     */
102
    protected function loadHelpers()
103
    {
104
        foreach (glob(__DIR__.'/Helpers/*.php') as $filename) {
105
            require_once $filename;
106
        }
107
    }
108
109
    /**
110
     * Register the publishers.
111
     *
112
     * @return void
113
     */
114
    protected function registerPublish()
115
    {
116
        $publishable = [
117
            'dbm.config' => [
118
                __DIR__.'/../config/dbm.php' => config_path('dbm.php'),
119
            ],
120
            'dbm.migrations' => [
121
                __DIR__.'/../database/migrations/' => database_path('migrations'),
122
            ],
123
            'dbm.seeds' => [
124
                __DIR__.'/../database/seeds/' => database_path('seeds'),
125
            ],
126
            'dbm.views' => [
127
                __DIR__.'/../resources/views' => resource_path('views/vendor/dbm/views'),
128
            ],
129
            'dbm.resources' => [
130
                __DIR__.'/../resources' => resource_path('views/vendor/dbm'),
131
            ],
132
        ];
133
134
        foreach ($publishable as $group => $paths) {
135
            $this->publishes($paths, $group);
0 ignored issues
show
Bug introduced by
The method publishes() does not exist on CodexShaper\DBM\ManagerServiceProvider. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

135
            $this->/** @scrutinizer ignore-call */ 
136
                   publishes($paths, $group);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
136
        }
137
    }
138
139
    /**
140
     * Register commands.
141
     *
142
     * @return void
143
     */
144
    private function registerCommands()
145
    {
146
        $this->commands(InstallDatabaseManager::class);
0 ignored issues
show
Bug introduced by
The method commands() does not exist on CodexShaper\DBM\ManagerServiceProvider. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

146
        $this->/** @scrutinizer ignore-call */ 
147
               commands(InstallDatabaseManager::class);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
147
        $this->commands(DatabaseAdmin::class);
148
        $this->commands(DatabaseBackup::class);
149
        $this->commands(DatabaseRestore::class);
150
        $this->commands(DatabaseSeed::class);
151
    }
152
}
153