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

MigrationCreator   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 0
loc 29
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A ensureMigrationDoesntAlreadyExist() 0 15 4
A getPath() 0 10 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