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