Completed
Push — master ( 7c9e2e...904e9e )
by Dmitry
11:28 queued 05:32
created

Bootstrap::run()   C

Complexity

Conditions 7
Paths 12

Size

Total Lines 29
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 7.2694

Importance

Changes 3
Bugs 2 Features 0
Metric Value
c 3
b 2
f 0
dl 0
loc 29
ccs 14
cts 17
cp 0.8235
rs 6.7272
cc 7
eloc 18
nc 12
nop 1
crap 7.2694
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 1
    public function run(Filesystem $fs)
14
    {
15 1
        $result = [];
16 1
        $cache = $fs->getPath('.cache');
17 1
        if (is_dir($cache)) {
18
            foreach ($fs->listFiles('.cache') as $file) {
19
                unlink($fs->getPath('.cache/'.$file));
20
            }
21
            rmdir($cache);
22
        }
23
24 1
        $procedures = $fs->listClasses('Procedure');
25 1
        if (count($procedures)) {
26 1
            foreach ($procedures as $procedure) {
27 1
                $this->get(Mapper::class)->getPlugin(Procedure::class)->register($procedure);
28
            }
29
        }
30
31 1
        $jobs = ['tarantool.migrate', 'tarantool.cache', 'module.defaults', 'module.register'];
32 1
        foreach ($jobs as $job) {
33
            try {
34 1
                $result[$job] = $this->dispatch($job);
35 1
            } catch (Exception $e) {
36 1
                $result[$job] = $e->getMessage();
37
            }
38
        }
39
40 1
        return $result;
41
    }
42
}
43