Completed
Push — master ( 0a305e...08804e )
by Mark
04:38 queued 03:25
created

ensureMigrationDoesntAlreadyExist()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.7666
c 0
b 0
f 0
cc 4
nc 4
nop 2
1
<?php
2
3
namespace Jaybizzle\MigrationsOrganiser;
4
5
use Illuminate\Database\Migrations\MigrationCreator as MC;
6
use InvalidArgumentException;
7
8
class MigrationCreator extends MC
9
{
10
    protected function ensureMigrationDoesntAlreadyExist($name, $migrationPath = null)
11
    {
12
        if (! empty($migrationPath)) {
13
            $migrationPath = $migrationPath.'/'.date('Y').'/'.date('m');
14
            $migrationFiles = $this->files->glob($migrationPath.'/*.php');
15
16
            foreach ($migrationFiles as $migrationFile) {
17
                $this->files->requireOnce($migrationFile);
18
            }
19
        }
20
21
        if (class_exists($className = $this->getClassName($name))) {
22
            throw new InvalidArgumentException("A {$className} class already exists.");
23
        }
24
    }
25
26
    protected function getPath($name, $path)
27
    {
28
        $path = $path.'/'.date('Y').'/'.date('m');
29
30
        if (! $this->files->exists($path)) {
31
            $this->files->makeDirectory($path, 0775, true);
32
        }
33
34
        return $path.'/'.$this->getDatePrefix().'_'.$name.'.php';
35
    }
36
}
37