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

Migrate   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 3
dl 0
loc 26
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B run() 0 23 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