Completed
Push — master ( b56897...b1778b )
by Dmitry
06:21
created

Application   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 90%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 13
c 1
b 0
f 0
lcom 1
cbo 3
dl 0
loc 67
ccs 36
cts 40
cp 0.9
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 20 2
B dispatch() 0 16 5
B get() 0 26 6
1
<?php
2
3
namespace Basis;
4
5
use League\Container\Container;
6
use League\Container\ReflectionContainer;
7
use Tarantool\Mapper\Mapper;
8
use Tarantool\Mapper\Plugin\Annotation;
9
use Tarantool\Mapper\Plugin\Procedure as ProcedurePlugin;
10
use Tarantool\Mapper\Procedure;
11
use Tarantool\Mapper\Repository;
12
13
class Application extends Container
14
{
15 17
    public function __construct(string $root)
16
    {
17 17
        parent::__construct();
18
19 17
        $fs = new Filesystem($this, $root);
20
21 17
        $this->share(Application::class, $this);
22 17
        $this->share(Container::class, $this);
23 17
        $this->share(Filesystem::class, $fs);
24
25 17
        $this->addServiceProvider(Provider\CoreProvider::class);
26 17
        $this->addServiceProvider(Provider\ServiceProvider::class);
27 17
        $this->addServiceProvider(Provider\TarantoolProvider::class);
28
29 17
        foreach ($fs->listClasses('Provider') as $provider) {
30 17
            $this->addServiceProvider($provider);
31
        }
32
33 17
        $this->delegate(new ReflectionContainer());
34 17
    }
35
36 11
    public function dispatch(string $job, array $params = [], string $service = null)
37
    {
38 11
        if ($service !== null) {
39
            if ($this->get(Service::class)->getName() == $service) {
40
                $service = null;
41
            }
42
        }
43
44 11
        $runner = $this->get(Runner::class);
45 11
        if ($service === null && $runner->hasJob($job)) {
46 11
            return $runner->dispatch($job, $params);
47
        }
48
49
        $dispatcher = $this->get(Dispatcher::class);
50
        return $dispatcher->dispatch($job, $params, $service);
51
    }
52
53 17
    public function get($alias, array $args = [])
54
    {
55 17
        if (!$this->hasShared($alias, true)) {
56 15
            $instance = null;
57 15
            if (is_subclass_of($alias, Procedure::class)) {
0 ignored issues
show
Bug introduced by
Due to PHP Bug #53727, is_subclass_of might return inconsistent results on some PHP versions if \Tarantool\Mapper\Procedure::class can be an interface. If so, you could instead use ReflectionClass::implementsInterface.
Loading history...
58 1
                $instance = $this->get(Mapper::class)
59 1
                    ->getPlugin(ProcedurePlugin::class)
60 1
                    ->get($alias);
61
            }
62 15
            if (is_subclass_of($alias, Repository::class)) {
0 ignored issues
show
Bug introduced by
Due to PHP Bug #53727, is_subclass_of might return inconsistent results on some PHP versions if \Tarantool\Mapper\Repository::class can be an interface. If so, you could instead use ReflectionClass::implementsInterface.
Loading history...
63 1
                $spaceName = $this->get(Mapper::class)
64 1
                    ->getPlugin(Annotation::class)
65 1
                    ->getRepositorySpaceName($alias);
66
67 1
                if ($spaceName) {
68 1
                    $instance = $this->get(Mapper::class)->getRepository($spaceName);
69
                }
70
            }
71 15
            if ($instance) {
72 2
                $this->share($alias, function () use ($instance) {
73 2
                    return $instance;
74 2
                });
75
            }
76
        }
77 17
        return parent::get($alias, $args);
78
    }
79
}
80