Completed
Push — master ( 8d9fcf...a0b939 )
by Dmitry
02:59
created

Bootstrap::run()   C

Complexity

Conditions 7
Paths 14

Size

Total Lines 28
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 7.0119

Importance

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