Completed
Push — master ( 9ff9d7...8b6791 )
by Dmitry
03:09
created

Migration   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
B run() 0 35 5
1
<?php
2
3
namespace Basis\Jobs\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 1
    public function run(Filesystem $filesystem, Framework $framework)
16
    {
17 1
        $time = time();
18 1
        $namespace = date('FY', $time);
19
20 1
        if(!is_array($this->name)) {
21 1
            $this->name = explode(' ', $this->name);
22 1
        }
23
24 1
        $class = '';
25 1
        foreach($this->name as $piece) {
26 1
            $class .= ucfirst($piece);
27 1
        }
28
29 1
        $template = $framework->getPath('resources/templates/migration.php');
30
31 1
        ob_start();
32 1
        include($template);
33 1
        $contents = ob_get_clean();
34
35 1
        $path = $filesystem->getPath('resources/migrations');
36 1
        if(!is_dir($path)) {
37 1
            mkdir($path);
38 1
        }
39
40 1
        $path = $filesystem->getPath('resources/migrations/'.date('Ym', $time));
41 1
        if(!is_dir($path)) {
42 1
            mkdir($path);
43 1
        }
44
45 1
        $filename = $path.'/'.$class.'.php';
46 1
        file_put_contents($filename, $contents);
47
48 1
        return compact('filename', 'namespace', 'class');
49
    }
50
}