Completed
Push — master ( e7b929...ba2691 )
by Dmitry
03:11
created

Migration   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 1
cbo 3
dl 0
loc 45
ccs 0
cts 31
cp 0
rs 10

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
    public function run(Filesystem $filesystem, Framework $framework)
17
    {
18
        $time = time();
19
        $namespace = date('FY', $time);
20
        $created_at = date('Y-m-d H:i:s', $time);
21
22
        if (!is_array($this->name)) {
23
            $this->name = explode(' ', $this->name);
24
        }
25
26
        if (!$this->name) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->name of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
27
            throw new Exception("No migration name defined!");
28
        }
29
30
        $class = '';
31
        foreach ($this->name as $piece) {
32
            $class .= ucfirst($piece);
33
        }
34
35
        $template = $framework->getPath('resources/templates/migration.php');
36
37
        ob_start();
38
        include($template);
39
        $contents = ob_get_clean();
40
41
        $path = $filesystem->getPath('php/Migration');
42
        if (!is_dir($path)) {
43
            mkdir($path);
44
        }
45
46
        $path = $filesystem->getPath('php/Migration/'.$namespace);
47
        if (!is_dir($path)) {
48
            mkdir($path);
49
        }
50
51
        $filename = 'php/Migration/'.$namespace.'/'.$class.'.php';
52
        file_put_contents($filename, $contents);
53
54
        return compact('filename', 'namespace', 'class');
55
    }
56
}
57