Completed
Push — master ( 04839b...f87650 )
by Dmitry
03:31
created

Bootstrap::run()   C

Complexity

Conditions 7
Paths 14

Size

Total Lines 30
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 7

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 30
ccs 17
cts 17
cp 1
rs 6.7272
cc 7
eloc 18
nc 14
nop 1
crap 7
1
<?php
2
3
namespace Basis\Job\Module;
4
5
use Basis\Filesystem;
6
use Basis\Procedure\Select;
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 3
                unlink($fs->getPath('.cache/'.$file));
23
            }
24
        }
25
26 4
        $procedures = $fs->listClasses('Procedure');
27 4
        if (count($procedures)) {
28 4
            foreach ($procedures as $procedure) {
29 4
                $this->get(Mapper::class)->getPlugin(Procedure::class)->register($procedure);
30
            }
31
        }
32
33 4
        foreach ($this->jobs as $job) {
34
            try {
35 4
                $result[$job] = $this->dispatch($job);
36 3
            } catch (Exception $e) {
37 4
                $result[$job] = $e->getMessage();
38
            }
39
        }
40
41 4
        $this->get(Mapper::class)->getPlugin(Procedure::class)
42 4
            ->register(Select::class);
43
44 4
        return $result;
45
    }
46
}
47