Completed
Push — master ( ea3156...ec95d0 )
by Dmitry
03:39
created

Migrate::run()   B

Complexity

Conditions 5
Paths 9

Size

Total Lines 23
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 5

Importance

Changes 0
Metric Value
dl 0
loc 23
ccs 15
cts 15
cp 1
rs 8.5906
c 0
b 0
f 0
cc 5
eloc 14
nc 9
nop 3
crap 5
1
<?php
2
3
namespace Basis\Job\Tarantool;
4
5
use Basis\Filesystem;
6
use ReflectionClass;
7
use Tarantool\Mapper\Bootstrap;
8
use Tarantool\Mapper\Mapper;
9
use Tarantool\Mapper\Plugin\Annotation;
10
11
class Migrate
12
{
13 2
    public function run(Mapper $mapper, Bootstrap $bootstrap, Filesystem $fs)
14
    {
15 2
        $mapper->getPlugin(Annotation::class)->migrate();
16
17 2
        $migrations = [];
18 2
        foreach ($fs->listClasses('Migration') as $class) {
19 1
            $reflection = new ReflectionClass($class);
20 1
            $created_at = $reflection->getDefaultProperties()['created_at'];
21 1
            if (!array_key_exists($created_at, $migrations)) {
22 1
                $migrations[$created_at] = [];
23
            }
24 1
            $migrations[$created_at][] = $class;
25
        }
26 2
        ksort($migrations);
27
28 2
        foreach ($migrations as $collection) {
29 1
            foreach ($collection as $class) {
30 1
                $bootstrap->register($class);
31
            }
32
        }
33
34 2
        $bootstrap->migrate();
35 2
    }
36
}
37