Migrate   A
last analyzed

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