Completed
Push — master ( 5e9169...e507aa )
by Dmitry
04:13
created

Migrate   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 90%

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 5
dl 0
loc 34
ccs 18
cts 20
cp 0.9
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B run() 0 31 7
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 42
    public function run(Mapper $mapper, Bootstrap $bootstrap, Filesystem $fs, Application $app)
17
    {
18 42
        $mapper->getPlugin(Annotation::class)->migrate();
19
20 42
        $migrations = [];
21 42
        foreach ($fs->listClasses('Migration') as $class) {
22 1
            $reflection = new ReflectionClass($class);
23 1
            $created_at = $reflection->getDefaultProperties()['created_at'];
24 1
            if (!array_key_exists($created_at, $migrations)) {
25 1
                $migrations[$created_at] = [];
26
            }
27 1
            $migrations[$created_at][] = $class;
28
        }
29 42
        ksort($migrations);
30
31 42
        foreach ($migrations as $collection) {
32 1
            foreach ($collection as $class) {
33 1
                if (method_exists($class, '__construct')) {
34
                    $class = $app->get($class);
35
                }
36 1
                $bootstrap->register($class);
37
            }
38
        }
39
40 42
        $bootstrap->migrate();
41
42 42
        $filename = $fs->getPath('.cache/mapper-meta.php');
43 42
        if (file_exists($filename)) {
44
            $this->dispatch('tarantool.cache');
45
        }
46 42
    }
47
}
48