Completed
Push — master ( bb44ed...9ef5f0 )
by Dmitry
02:40
created

Application   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 90.24%

Importance

Changes 0
Metric Value
wmc 13
lcom 1
cbo 3
dl 0
loc 68
ccs 37
cts 41
cp 0.9024
rs 10
c 0
b 0
f 0

3 Methods

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