Completed
Push — master ( 692570...6b6f8f )
by Dmitry
03:35
created

Migrate   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 50%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 6
lcom 0
cbo 5
dl 0
loc 30
ccs 9
cts 18
cp 0.5
rs 10
c 2
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B run() 0 27 6
1
<?php
2
3
namespace Basis\Job\Tarantool;
4
5
use Basis\Application;
6
use Basis\Filesystem;
7
use Basis\Job;
8
use ReflectionClass;
9
use Tarantool\Mapper\Bootstrap;
10
use Tarantool\Mapper\Mapper;
11
use Tarantool\Mapper\Plugin\Annotation;
12
use Tarantool\Mapper\Plugin\Sequence;
13
14
class Migrate extends Job
15
{
16 1
    public function run(Mapper $mapper, Bootstrap $bootstrap, Filesystem $fs, Application $app)
17
    {
18 1
        $mapper->getPlugin(Annotation::class)->migrate();
19 1
        $mapper->getPlugin(Sequence::class)->initSchema();
20
21 1
        $migrations = [];
22 1
        foreach ($fs->listClasses('Migration') as $class) {
23
            $reflection = new ReflectionClass($class);
24
            $created_at = $reflection->getDefaultProperties()['created_at'];
25
            if (!array_key_exists($created_at, $migrations)) {
26
                $migrations[$created_at] = [];
27
            }
28
            $migrations[$created_at][] = $class;
29
        }
30 1
        ksort($migrations);
31
32 1
        foreach ($migrations as $collection) {
33
            foreach ($collection as $class) {
34
                if (method_exists($class, '__construct')) {
35
                    $class = $app->get($class);
36
                }
37
                $bootstrap->register($class);
38
            }
39
        }
40
41 1
        $bootstrap->migrate();
42 1
    }
43
}
44