Completed
Push — master ( 055a24...772acc )
by Dmitry
03:57
created

Migrate::run()   B

Complexity

Conditions 6
Paths 12

Size

Total Lines 27
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 6.0061

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 27
ccs 17
cts 18
cp 0.9444
rs 8.439
cc 6
eloc 17
nc 12
nop 4
crap 6.0061
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 2
    public function run(Mapper $mapper, Bootstrap $bootstrap, Filesystem $fs, Application $app)
17
    {
18 2
        $mapper->getPlugin(Annotation::class)->migrate();
19 2
        $mapper->getPlugin(Sequence::class)->initSchema();
20
21 2
        $migrations = [];
22 2
        foreach ($fs->listClasses('Migration') as $class) {
23 1
            $reflection = new ReflectionClass($class);
24 1
            $created_at = $reflection->getDefaultProperties()['created_at'];
25 1
            if (!array_key_exists($created_at, $migrations)) {
26 1
                $migrations[$created_at] = [];
27
            }
28 1
            $migrations[$created_at][] = $class;
29
        }
30 2
        ksort($migrations);
31
32 2
        foreach ($migrations as $collection) {
33 1
            foreach ($collection as $class) {
34 1
                if (method_exists($class, '__construct')) {
35
                    $class = $app->get($class);
36
                }
37 1
                $bootstrap->register($class);
38
            }
39
        }
40
41 2
        $bootstrap->migrate();
42 2
    }
43
}
44