Passed
Push — next ( 3b41f7...f014dd )
by Bas
02:34
created

CommandServiceProvider::boot()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

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