Completed
Push — master ( f0a08a...a3469c )
by Dmitry
05:34
created

Bootstrap::run()   C

Complexity

Conditions 7
Paths 12

Size

Total Lines 31
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 7.0084

Importance

Changes 4
Bugs 2 Features 0
Metric Value
c 4
b 2
f 0
dl 0
loc 31
ccs 17
cts 18
cp 0.9444
rs 6.7272
cc 7
eloc 19
nc 12
nop 1
crap 7.0084
1
<?php
2
3
namespace Basis\Job\Module;
4
5
use Basis\Filesystem;
6
use Basis\Procedure\IndexInArray;
7
use Basis\Job;
8
use Exception;
9
use Tarantool\Mapper\Mapper;
10
use Tarantool\Mapper\Plugin\Procedure;
11
12
class Bootstrap extends Job
13
{
14
    public $jobs = ['tarantool.migrate', 'tarantool.cache', 'module.defaults', 'module.register'];
15
16 4
    public function run(Filesystem $fs)
17
    {
18 4
        $result = [];
19 4
        $cache = $fs->getPath('.cache');
20 4
        if (is_dir($cache)) {
21 4
            foreach ($fs->listFiles('.cache') as $file) {
22
                unlink($fs->getPath('.cache/'.$file));
23
            }
24 4
            rmdir($cache);
25
        }
26
27 4
        $procedures = $fs->listClasses('Procedure');
28 4
        if (count($procedures)) {
29 4
            foreach ($procedures as $procedure) {
30 4
                $this->get(Mapper::class)->getPlugin(Procedure::class)->register($procedure);
31
            }
32
        }
33
34 4
        $this->get(Mapper::class)->getPlugin(Procedure::class)
35 4
            ->register(IndexInArray::class);
36
37 4
        foreach ($this->jobs as $job) {
38
            try {
39 4
                $result[$job] = $this->dispatch($job);
40 4
            } catch (Exception $e) {
41 4
                $result[$job] = $e->getMessage();
42
            }
43
        }
44
45 4
        return $result;
46
    }
47
}
48