Create   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 15
dl 0
loc 36
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 2
A run() 0 12 2
1
<?php
2
3
namespace Vados\MigrationRunner\command;
4
5
use Vados\MigrationRunner\providers\PathProvider;
6
7
/**
8
 * Class Create
9
 * @package Vados\MigrationRunner\command
10
 */
11
class Create implements ICommand
12
{
13
    /**
14
     * @var array
15
     */
16
    private $params;
17
18
    /**
19
     * @var string
20
     */
21
    private $migrationName = '';
22
23
    /**
24
     * Create constructor.
25
     * @param array $params
26
     */
27
    public function __construct(array $params)
28
    {
29
        $this->params = $params;
30
        if (isset($params[0])) {
31
            $this->migrationName = $params[0];
32
        }
33
    }
34
35
    public function run()
36
    {
37
        if (!is_dir(PathProvider::getMigrationDir())) {
38
            mkdir(PathProvider::getMigrationDir());
39
        }
40
        $migrationFile = file_get_contents(__DIR__ . '/../migration/Template');
41
        $timestamp = time();
42
        $migrationFile = str_replace('{{timestamp}}', $timestamp, $migrationFile);
43
        $migrationFile = str_replace('{{migrationName}}', $this->migrationName, $migrationFile);
44
        $filename = PathProvider::getMigrationDir() . "/m{$timestamp}_{$this->migrationName}.php";
45
        file_put_contents($filename, $migrationFile);
46
        echo "Migration $filename created!" . PHP_EOL;
47
    }
48
}