Passed
Push — dependabot/github_actions/depe... ( d1016c )
by
unknown
11:16
created

CommandServiceProvider::provides()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 7
c 0
b 0
f 0
dl 0
loc 9
ccs 0
cts 8
cp 0
rs 10
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace LaravelFreelancerNL\Aranguent\Providers;
4
5
use Illuminate\Database\MigrationServiceProvider as IlluminateMigrationServiceProvider;
6
use LaravelFreelancerNL\Aranguent\Console\Migrations\AranguentConvertMigrationsCommand;
7
use LaravelFreelancerNL\Aranguent\Console\Migrations\MigrateMakeCommand;
8
use LaravelFreelancerNL\Aranguent\Console\ModelMakeCommand;
9
use LaravelFreelancerNL\Aranguent\Migrations\DatabaseMigrationRepository;
10
use LaravelFreelancerNL\Aranguent\Migrations\MigrationCreator;
11
12
class CommandServiceProvider extends IlluminateMigrationServiceProvider
13
{
14
    protected $defer = true;
15
16 217
    public function boot()
17
    {
18 217
        if ($this->app->runningInConsole()) {
19 217
            $this->commands([
20 217
                MigrateMakeCommand::class,
21 217
                ModelMakeCommand::class,
22 217
            ]);
23
        }
24
    }
25
26
    /**
27
     * Register the service provider.
28
     *
29
     * @return void
30
     */
31 217
    public function register()
32
    {
33 217
        $this->registerRepository();
34
35 217
        $this->registerMigrator();
36
37 217
        $this->registerCreator();
38
39 217
        $commands = array_merge(
40 217
            $this->commands,
41 217
            [
42 217
                'AranguentConvertMigrations' => 'command.aranguent.convert-migrations',
43 217
                'MigrateMake' => 'command.migrate.make',
44 217
                'ModelMake' => 'command.model.aranguent',
45 217
            ]
46 217
        );
47 217
        $this->registerCommands($commands);
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53 217
    protected function registerRepository()
54
    {
55 217
        $this->app->singleton('migration.repository', function ($app) {
56 217
            $collection = $app['config']['database.migrations'];
57
58 217
            return new DatabaseMigrationRepository($app['db'], $collection);
59 217
        });
60
    }
61
62 217
    protected function registerCreator()
63
    {
64 217
        $this->app->singleton('migration.creator', function ($app) {
65 217
            $customStubPath = __DIR__.'/../../stubs';
66
67 217
            return new MigrationCreator($app['files'], $customStubPath);
68 217
        });
69
    }
70
71
    /**
72
     * Register the command.
73
     *
74
     * @return void
75
     */
76 217
    protected function registerMigrateMakeCommand()
77
    {
78 217
        $this->app->singleton('command.migrate.make', function ($app) {
79 217
            $creator = $app['migration.creator'];
80
81 217
            $composer = $app['composer'];
82
83 217
            return new MigrateMakeCommand($creator, $composer);
84 217
        });
85
    }
86
87 217
    protected function registerModelMakeCommand()
88
    {
89 217
        $this->app->singleton('command.model.aranguent', function ($app) {
90 217
            return new ModelMakeCommand($app['files']);
91 217
        });
92
    }
93
94 217
    protected function registerAranguentConvertMigrationsCommand()
95
    {
96 217
        $this->app->singleton('command.aranguent.convert-migrations', function ($app) {
97 217
            return new AranguentConvertMigrationsCommand($app['migrator']);
98 217
        });
99
    }
100
101
    public function provides()
102
    {
103
        return [
104
            'migrator',
105
            'migration.creator',
106
            'migration.repository',
107
            'command.aranguent.convert-migrations',
108
            'command.migrate.make',
109
            'command.model.aranguent',
110
        ];
111
    }
112
}
113