Completed
Push — master ( 3f30e7...37b632 )
by Dmitry
08:21
created

Bootstrap::run()   B

Complexity

Conditions 9
Paths 54

Size

Total Lines 34

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 9.0945

Importance

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