Completed
Push — master ( cb1113...b09b3a )
by Maarten
16s queued 11s
created

DeletesMigrations::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Mtolhuys\LaravelSchematics\Actions\Migration\Traits;
4
5
use Mtolhuys\LaravelSchematics\Models\Migration;
6
use Mtolhuys\LaravelSchematics\Services\ClassReader;
7
8
trait DeletesMigrations
9
{
10
    public
11
        $autoMigrate,
12
        $filename,
13
        $path;
14
15
    public function __construct()
16
    {
17
        $this->autoMigrate = config('schematics.auto-migrate');
18
        $this->path = database_path('migrations');
19
    }
20
21
    /**
22
     * Running down in case auto-migrate is turned on
23
     *
24
     * @param $migration
25
     */
26
    public function down($migration)
27
    {
28
        $file = "$this->path/$migration";
29
30
        require_once $file;
31
32
        Migration::where('migration', pathinfo($migration, PATHINFO_FILENAME))->delete();
33
34
        $migration = ClassReader::getClassName($file);
35
36
        try {
37
            (new $migration)->down();
38
        } catch (\Throwable $e) {}
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
39
    }
40
}
41