Completed
Push — master ( 3f30e7...37b632 )
by Dmitry
08:21
created

Migrate   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 90.48%

Importance

Changes 0
Metric Value
wmc 8
lcom 0
cbo 2
dl 0
loc 35
ccs 19
cts 21
cp 0.9048
rs 10
c 0
b 0
f 0

1 Method

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