Passed
Push — feature/laravel-11-support ( 6c6616...4492de )
by Bas
04:19 queued 15s
created

CommandServiceProvider::provides()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LaravelFreelancerNL\Aranguent\Providers;
6
7
use LaravelFreelancerNL\Aranguent\Console\DbCommand;
8
use Illuminate\Database\Console\DbCommand as IlluminateDbCommand;
9
use LaravelFreelancerNL\Aranguent\Console\ModelMakeCommand;
10
use Illuminate\Support\ServiceProvider;
11
12
class CommandServiceProvider extends ServiceProvider
13
{
14
    protected bool $defer = false;
15
16
    /**
17
     * The commands to be registered.
18
     *
19
     * @var string[]
20
     */
21
    protected $commands = [
22
        'ModelMake' => ModelMakeCommand::class,
23
        'Db' => DbCommand::class,
24
    ];
25
26
27
    /**
28
     * Register the service provider.
29
     *
30
     * @return void
31
     */
32 350
    public function register()
33
    {
34 350
        $this->registerCommands($this->commands);
35
    }
36
37
    /**
38
     * Register the given commands.
39
     *
40
     * @param  string[]  $commands
41
     * @return void
42
     */
43 350
    protected function registerCommands(array $commands)
44
    {
45 350
        foreach (array_keys($commands) as $command) {
46 350
            $this->{"register{$command}Command"}();
47
        }
48
49 350
        $this->commands(array_values($commands));
50
    }
51
52 350
    protected function registerModelMakeCommand(): void
53
    {
54 350
        $this->app->singleton(ModelMakeCommand::class, function ($app) {
55 350
            return new ModelMakeCommand($app['files']);
56 350
        });
57
    }
58
59 350
    protected function registerDbCommand(): void
60
    {
61 350
        $this->app->extend(IlluminateDbCommand::class, function () {
62
            return new DbCommand();
63 350
        });
64
    }
65
66
    /**
67
     * @return string[]
68
     */
69
    public function provides()
70
    {
71
        return array_values($this->commands);
72
    }
73
}
74