MigrateMakeCommand::writeMigration()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 5
Bugs 0 Features 0
Metric Value
eloc 7
c 5
b 0
f 0
dl 0
loc 17
rs 10
cc 2
nc 2
nop 3
1
<?php
2
3
namespace Orkhanahmadov\ContentMigrations\Console;
4
5
use Illuminate\Database\Console\Migrations\MigrateMakeCommand as Command;
6
use Illuminate\Support\Collection;
7
use Illuminate\Support\Str;
8
9
class MigrateMakeCommand extends Command
10
{
11
    protected $signature = 'make:content-migration {name : The name of the content migration}';
12
13
    protected $description = 'Create a new content migration file';
14
15
    public function handle()
16
    {
17
        $name = Str::snake(trim($this->input->getArgument('name')));
0 ignored issues
show
Bug introduced by
It seems like $this->input->getArgument('name') can also be of type string[]; however, parameter $str of trim() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

17
        $name = Str::snake(trim(/** @scrutinizer ignore-type */ $this->input->getArgument('name')));
Loading history...
18
19
        $this->writeMigration($name);
20
21
        $this->composer->dumpAutoloads();
22
    }
23
24
    protected function writeMigration($name, $table = null, $create = null)
25
    {
26
        // Needed for Laravel 6 and 7 support. Laravel 8 handles creating folder automatically
27
        // @codeCoverageIgnoreStart
28
        if (! file_exists(database_path('content-migrations'))) {
29
            mkdir(database_path('content-migrations'), 0755);
30
        }
31
        // @codeCoverageIgnoreEnd
32
33
        $file = $this->creator->create(
34
            $name,
35
            $this->laravel->databasePath() . DIRECTORY_SEPARATOR . 'content-migrations'
36
        );
37
38
        $fileName = basename($file);
39
40
        $this->line("<info>Created Content Migration:</info> {$fileName}");
41
    }
42
}
43