Passed
Push — next ( d224bd...9e651f )
by Bas
15:29 queued 11:57
created

MigrateMakeCommand   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 90
Duplicated Lines 0 %

Test Coverage

Coverage 16%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 24
c 1
b 0
f 0
dl 0
loc 90
ccs 4
cts 25
cp 0.16
rs 10
wmc 8

3 Methods

Rating   Name   Duplication   Size   Complexity  
A writeMigration() 0 10 1
A __construct() 0 6 1
A handle() 0 36 6
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LaravelFreelancerNL\Aranguent\Console\Migrations;
6
7
use Illuminate\Database\Console\Migrations\MigrateMakeCommand as IlluminateMigrateMakeCommand;
8
use Illuminate\Database\Console\Migrations\TableGuesser;
9
use Illuminate\Support\Composer;
10
use Illuminate\Support\Str;
11
use LaravelFreelancerNL\Aranguent\Migrations\MigrationCreator;
12
13
class MigrateMakeCommand extends IlluminateMigrateMakeCommand
14
{
15
    /**
16
     * The console command signature.
17
     *
18
     * @var string
19
     */
20
    protected $signature = 'make:migration {name : The name of the migration}
21
        {--create= : The collection to be created}
22
        {--collection= : The collection to migrate}
23
        {--table= : (Alias for collection)}
24
        {--path= : The location where the migration file should be created}
25
        {--realpath : Indicate any provided migration file paths are pre-resolved absolute paths}';
26
27
    /**
28
     * Create a new migration install command instance.
29
     */
30 310
    public function __construct(MigrationCreator $creator, Composer $composer)
31
    {
32 310
        $this->creator = $creator;
33 310
        $this->composer = $composer;
0 ignored issues
show
Deprecated Code introduced by
The property Illuminate\Database\Cons...eMakeCommand::$composer has been deprecated: Will be removed in a future Laravel version. ( Ignorable by Annotation )

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

33
        /** @scrutinizer ignore-deprecated */ $this->composer = $composer;

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
34
35 310
        parent::__construct($creator, $composer);
36
    }
37
38
    /**
39
     * Execute the console command.
40
     *
41
     * @return void
42
     *
43
     * @throws \Exception
44
     */
45
    public function handle()
46
    {
47
        // It's possible for the developer to specify the tables to modify in this
48
        // schema operation. The developer may also specify if this table needs
49
        // to be freshly created so we can create the appropriate migrations.
50
        $name = Str::snake(trim((string) $this->input->getArgument('name')));
51
52
        $collection = $this->input->getOption('collection');
53
        if (!$collection) {
54
            $collection = $this->input->getOption('table');
55
        }
56
57
        $create = $this->input->getOption('create') ?: false;
58
59
        // If no table was given as an option but a create option is given then we
60
        // will use the "create" option as the table name. This allows the devs
61
        // to pass a table name into this option as a short-cut for creating.
62
        if (!$collection && is_string($create)) {
63
            $collection = $create;
64
65
            $create = true;
66
        }
67
68
        // Next, we will attempt to guess the table name if this the migration has
69
        // "create" in the name. This will allow us to provide a convenient way
70
        // of creating migrations that create new tables for the application.
71
        if (!$collection) {
72
            [$collection, $create] = TableGuesser::guess($name);
73
        }
74
75
        // Now we are ready to write the migration out to disk. Once we've written
76
        // the migration out, we will dump-autoload for the entire framework to
77
        // make sure that the migrations are registered by the class loaders.
78
        $this->writeMigration($name, $collection, $create);
79
80
        $this->composer->dumpAutoloads();
0 ignored issues
show
Deprecated Code introduced by
The property Illuminate\Database\Cons...eMakeCommand::$composer has been deprecated: Will be removed in a future Laravel version. ( Ignorable by Annotation )

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

80
        /** @scrutinizer ignore-deprecated */ $this->composer->dumpAutoloads();

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
81
    }
82
83
    /**
84
     * Write the migration file to disk.
85
     *
86
     * @param  string  $name
87
     * @param  string  $collection
88
     * @param  bool  $create
89
     * @return void
90
     *
91
     * @throws \Exception
92
     */
93
    protected function writeMigration($name, $collection, $create)
94
    {
95
        $file = pathinfo($this->creator->create(
96
            $name,
97
            $this->getMigrationPath(),
98
            $collection,
99
            $create
100
        ), PATHINFO_FILENAME);
101
102
        $this->line("<info>Created Migration:</info> {$file}");
103
    }
104
}
105