Completed
Push — master ( 8260b5...6e390f )
by Dmitry
08:05
created

Migration   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 41
ccs 0
cts 28
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B run() 0 36 5
1
<?php
2
3
namespace Basis\Job\Generate;
4
5
use Basis\Framework;
6
use Basis\Filesystem;
7
8
/**
9
 * Generate tarantool migration
10
 */
11
class Migration
12
{
13
    public $name;
14
15
    public function run(Filesystem $filesystem, Framework $framework)
16
    {
17
        $time = time();
18
        $namespace = date('FY', $time);
19
        $created_at = date('Y-m-d H:i:s', $time);
20
21
        if (!is_array($this->name)) {
22
            $this->name = explode(' ', $this->name);
23
        }
24
25
        $class = '';
26
        foreach ($this->name as $piece) {
27
            $class .= ucfirst($piece);
28
        }
29
30
        $template = $framework->getPath('resources/templates/migration.php');
31
32
        ob_start();
33
        include($template);
34
        $contents = ob_get_clean();
35
36
        $path = $filesystem->getPath('php/Migration');
37
        if (!is_dir($path)) {
38
            mkdir($path);
39
        }
40
41
        $path = $filesystem->getPath('php/Migration/'.$namespace);
42
        if (!is_dir($path)) {
43
            mkdir($path);
44
        }
45
46
        $filename = 'php/Migration/'.$namespace.'/'.$class.'.php';
47
        file_put_contents($filename, $contents);
48
49
        return compact('filename', 'namespace', 'class');
50
    }
51
}
52