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

Migrate   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 94.12%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 0
cbo 4
dl 0
loc 29
ccs 16
cts 17
cp 0.9412
rs 10

1 Method

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