Migrate::run()   B
last analyzed

Complexity

Conditions 8
Paths 32

Size

Total Lines 32

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 19
CRAP Score 8.0551

Importance

Changes 0
Metric Value
dl 0
loc 32
ccs 19
cts 21
cp 0.9048
rs 8.1635
c 0
b 0
f 0
cc 8
nc 32
nop 1
crap 8.0551
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