Completed
Push — master ( fe2434...bffc01 )
by Dmitry
03:47
created

Bootstrap::run()   C

Complexity

Conditions 7
Paths 36

Size

Total Lines 33
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 56

Importance

Changes 4
Bugs 0 Features 0
Metric Value
c 4
b 0
f 0
dl 0
loc 33
ccs 0
cts 28
cp 0
rs 6.7272
cc 7
eloc 20
nc 36
nop 5
crap 56
1
<?php
2
3
namespace Basis\Jobs\Module;
4
5
use Basis\Converter;
6
use Basis\Event;
7
use Basis\Filesystem;
8
use Basis\Framework;
9
use Basis\Runner;
10
use Basis\Service;
11
use Exception;
12
use ReflectionClass;
13
use ReflectionProperty;
14
15
class Bootstrap
16
{
17
    public function run(Runner $runner, Service $service, Event $event, Framework $framework, Filesystem $fs)
18
    {
19
        $runner->dispatch('tarantool.migrate');
20
21
        $meta = $runner->dispatch('module.meta');
22
        foreach ($meta['jobs'] as $job) {
23
            $class = new ReflectionClass($runner->getJobClass($job));
24
            $params = [];
25
            foreach ($class->getProperties(ReflectionProperty::IS_PUBLIC) as $property) {
26
                $params[] = $property->getName();
27
            }
28
            $service->registerJob($job, $params);
29
        }
30
31
        foreach ($meta['routes'] as $route) {
32
            $service->registerRoute($route);
33
        }
34
35
        foreach ($event->getSubscription() as $event => $listeners) {
0 ignored issues
show
Bug introduced by
It seems like $event is not always an object, but can also be of type integer|string. Maybe add an additional type check?

If a variable is not always an object, we recommend to add an additional type check to ensure your method call is safe:

function someFunction(A $objectMaybe = null)
{
    if ($objectMaybe instanceof A) {
        $objectMaybe->doSomething();
    }
}
Loading history...
36
            $service->subscribe($event);
37
        }
38
39
        $assets = $runner->dispatch('module.assets');
40
        $service->updateAssetsVersion($assets['hash']);
41
42
        foreach ($framework->listFiles('resources/defaults') as $file) {
43
            if (!$fs->exists($file)) {
44
                $source = $framework->getPath("resources/defaults/$file");
45
                $destination = $fs->getPath($file);
46
                file_put_contents($destination, file_get_contents($source));
47
            }
48
        }
49
    }
50
}
51