Migration   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 95.83%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 0
loc 45
ccs 23
cts 24
cp 0.9583
rs 10
c 0
b 0
f 0

1 Method

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