Completed
Push — master ( 6e390f...5a6d30 )
by Dmitry
07:10 queued 04:24
created

Migrate::run()   B

Complexity

Conditions 6
Paths 12

Size

Total Lines 26
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 6.0073

Importance

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