Completed
Push — master ( c70864...b6d4e5 )
by Dmitry
03:30 queued 27s
created

Bootstrap   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 3
dl 0
loc 37
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B run() 0 32 8
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 4
                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 3
                $result[$job] = $e->getMessage();
38
            }
39
        }
40
41 4
        if ($this->app->has(Mapper::class)) {
42 4
            $this->get(Mapper::class)->getPlugin(Procedure::class)
43 4
                ->register(Select::class);
44
        }
45
46 4
        return $result;
47
    }
48
}
49