Completed
Push — master ( 2761e7...346e09 )
by Dmitry
05:23
created

Migrate::run()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 20
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 4.7861

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 20
ccs 5
cts 12
cp 0.4167
rs 9.4285
cc 3
eloc 11
nc 3
nop 3
crap 4.7861
1
<?php
2
3
namespace Basis\Jobs\Tarantool;
4
5
use Basis\Filesystem;
6
use Tarantool\Mapper\Bootstrap;
7
use Tarantool\Mapper\Mapper;
8
use Tarantool\Mapper\Plugins\Annotation;
9
10
class Migrate
11
{
12 1
    public function run(Mapper $mapper, Bootstrap $bootstrap, Filesystem $fs)
13
    {
14 1
        $mapper->getPlugin(Annotation::class)->migrate();
15
16 1
        foreach($fs->listFiles('resources/migrations') as $path) {
17
18
            list($ym, $filename) = explode('/', $path);
19
            $namespace = date_create_from_format('Ym', $ym)->format('FY');
20
21
            list($date, $time, $name) = explode('_', substr($filename, 0, -4));
22
            $class = $namespace.'\\'.$name;
23
24
            if(!class_exists($class, false)) {
25
                include $fs->getPath('resources/migrations/'.$path);
26
            }
27
            $bootstrap->register($class);
28
        }
29
30 1
        $bootstrap->migrate();
31 1
    }
32
}
33