Bootstrap::run()   B
last analyzed

Complexity

Conditions 10
Paths 72

Size

Total Lines 39

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 10.6913

Importance

Changes 0
Metric Value
dl 0
loc 39
ccs 17
cts 21
cp 0.8095
rs 7.6666
c 0
b 0
f 0
cc 10
nc 72
nop 1
crap 10.6913

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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
        try {
28 1
            foreach ([Framework::class, Filesystem::class] as $source) {
29 1
                $procedures = $this->get($source)->listClasses('Procedure');
30 1
                if (count($procedures)) {
31 1
                    foreach ($procedures as $procedure) {
32 1
                        $this->get(Mapper::class)->getPlugin(Procedure::class)->register($procedure);
33
                    }
34
                }
35
            }
36
        } catch (Exception $e) {
37
            // ignore issues on procedure registration
38
            $result['procedures'] = $e->getMessage();
39
        }
40
41 1
        foreach ($this->jobs as $job) {
42
            try {
43 1
                $result[$job] = $this->dispatch($job);
44
            } catch (Exception $e) {
45
                $result[$job] = $e->getMessage();
46
            }
47
        }
48
49 1
        if ($this->app->has(Mapper::class)) {
50 1
            $this->get(Mapper::class)->getPlugin(Procedure::class)
51 1
                ->register(Select::class);
52
        }
53
54 1
        return $result;
55
    }
56
}
57