Completed
Push — master ( 4848aa...64d9da )
by Dmitry
03:44
created

Application   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 58.14%

Importance

Changes 0
Metric Value
wmc 13
lcom 1
cbo 3
dl 0
loc 70
ccs 25
cts 43
cp 0.5814
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
B dispatch() 0 16 5
B get() 0 26 6
A __construct() 0 23 2
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
    public function __construct(string $root)
16
    {
17
        parent::__construct();
18
19
        $fs = new Filesystem($this, $root);
20
21
        $this->share(Application::class, $this);
22
        $this->share(Container::class, $this);
23
        $this->share(Filesystem::class, $fs);
24
25
        $this->addServiceProvider(Provider\GuzzleProvider::class);
26
        $this->addServiceProvider(Provider\CoreProvider::class);
27
        $this->addServiceProvider(Provider\PoolProvider::class);
28
        $this->addServiceProvider(Provider\ServiceProvider::class);
29
        $this->addServiceProvider(Provider\TarantoolProvider::class);
30
        $this->addServiceProvider(Provider\ClickhouseProvider::class);
31
32
        foreach ($fs->listClasses('Provider') as $provider) {
33
            $this->addServiceProvider($provider);
34
        }
35
36
        $this->delegate(new ReflectionContainer());
37
    }
38
39 31
    public function dispatch(string $job, array $params = [], string $service = null)
40
    {
41 31
        if ($service !== null) {
42
            if ($this->get(Service::class)->getName() == $service) {
43
                $service = null;
44
            }
45
        }
46
47 31
        $runner = $this->get(Runner::class);
48 31
        if ($service === null && $runner->hasJob($job)) {
49 31
            return $runner->dispatch($job, $params);
50
        }
51
52 1
        $dispatcher = $this->get(Dispatcher::class);
53 1
        return $dispatcher->dispatch($job, $params, $service);
54
    }
55
56 31
    public function get($alias, array $args = [])
57
    {
58 31
        if (!$this->hasShared($alias, true)) {
59 31
            $instance = null;
60 31
            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...
61 1
                $instance = $this->get(Mapper::class)
62 1
                    ->getPlugin(ProcedurePlugin::class)
63 1
                    ->get($alias);
64
            }
65 31
            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...
66 1
                $spaceName = $this->get(Mapper::class)
67 1
                    ->getPlugin(Annotation::class)
68 1
                    ->getRepositorySpaceName($alias);
69
70 1
                if ($spaceName) {
71 1
                    $instance = $this->get(Mapper::class)->getRepository($spaceName);
72
                }
73
            }
74 31
            if ($instance) {
75 2
                $this->share($alias, function () use ($instance) {
76 2
                    return $instance;
77 2
                });
78
            }
79
        }
80 31
        return parent::get($alias, $args);
81
    }
82
}
83