Completed
Pull Request — master (#3)
by
unknown
02:46
created

MigrateMakeCommand::writeMigration()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
eloc 7
c 4
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')));
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));
0 ignored issues
show
Bug introduced by
A parse error occurred: Syntax error, unexpected ')' on line 29 at column 60
Loading history...
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