Passed
Push — master ( 76148c...952ce9 )
by Orkhan
02:09 queued 10s
created

MigrateCommand::prepareAndRun()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Orkhanahmadov\ContentMigrations\Console;
4
5
use Illuminate\Database\Console\Migrations\MigrateCommand as Command;
6
7
class MigrateCommand extends Command
8
{
9
    protected $signature = 'content-migrate {--database= : The database connection to use}
10
                {--schema-path= : The path to a schema dump file}
11
                {--pretend : Dump the SQL queries that would be run}';
12
13
    protected $description = 'Run the content migrations';
14
15
    public function handle()
16
    {
17
        // Needed for Laravel 6 support. Laravel 7 and 8 has 'usingConnection' method on Migrator
18
        if (method_exists($this->migrator, 'usingConnection')) {
19
            $this->migrator->usingConnection($this->option('database'), function () {
20
                $this->prepareAndRun();
21
            });
22
        } else {
23
            // @codeCoverageIgnoreStart
24
            $this->prepareAndRun();
25
            // @codeCoverageIgnoreEnd
26
        }
27
28
        return 0;
29
    }
30
31
    protected function prepareAndRun(): void
32
    {
33
        $this->prepareDatabase();
34
35
        $this->migrator->setOutput($this->output)->run($this->getMigrationPaths());
36
    }
37
38
    protected function prepareDatabase()
39
    {
40
        if (! $this->migrator->repositoryExists()) {
41
            $this->call('content-migrate:install', array_filter([
42
                '--database' => $this->option('database'),
43
            ]));
44
        }
45
46
        if (method_exists($this->migrator, 'hasRunAnyMigrations') &&
47
            ! $this->migrator->hasRunAnyMigrations() &&
48
            ! $this->option('pretend')) {
49
            $this->loadSchemaState();
0 ignored issues
show
Bug introduced by
The method loadSchemaState() does not exist on Orkhanahmadov\ContentMig...\Console\MigrateCommand. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

49
            $this->/** @scrutinizer ignore-call */ 
50
                   loadSchemaState();
Loading history...
50
        }
51
    }
52
53
    protected function getMigrationPath()
54
    {
55
        return $this->laravel->databasePath() . DIRECTORY_SEPARATOR . 'content-migrations';
56
    }
57
}
58