Completed
Push — master ( 13738a...da5e92 )
by Dmitry
07:09 queued 05:43
created

Bootstrap::run()   B

Complexity

Conditions 8
Paths 28

Size

Total Lines 32

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 8.0877

Importance

Changes 0
Metric Value
dl 0
loc 32
ccs 16
cts 18
cp 0.8889
rs 8.1635
c 0
b 0
f 0
cc 8
nc 28
nop 1
crap 8.0877
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 1
    public function run(Filesystem $fs)
17
    {
18 1
        $result = [];
19 1
        $cache = $fs->getPath('.cache');
20 1
        if (is_dir($cache)) {
21 1
            foreach ($fs->listFiles('.cache') as $file) {
22 1
                unlink($fs->getPath('.cache/'.$file));
23
            }
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
            } catch (Exception $e) {
37
                $result[$job] = $e->getMessage();
38
            }
39
        }
40
41 1
        if ($this->app->has(Mapper::class)) {
42 1
            $this->get(Mapper::class)->getPlugin(Procedure::class)
43 1
                ->register(Select::class);
44
        }
45
46 1
        return $result;
47
    }
48
}
49