Completed
Push — master ( ca2e77...8cea3f )
by Dmitry
04:18
created

Application::get()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 8.7414

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 14
ccs 3
cts 9
cp 0.3333
rs 9.2
cc 4
eloc 9
nc 3
nop 2
crap 8.7414
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\Repository;
10
11
class Application extends Container
12
{
13 11
    public function __construct($root)
14
    {
15 11
        parent::__construct();
16
17 11
        $fs = new Filesystem($this, $root);
18
19 11
        $this->share(Application::class, $this);
20 11
        $this->share(Container::class, $this);
21 11
        $this->share(Filesystem::class, $fs);
22
23 11
        $this->addServiceProvider(Provider\CoreProvider::class);
24 11
        $this->addServiceProvider(Provider\ServiceProvider::class);
25 11
        $this->addServiceProvider(Provider\TarantoolProvider::class);
26
27 11
        foreach ($fs->listClasses('Provider') as $provider) {
28 11
            $this->addServiceProvider($provider);
29
        }
30
31 11
        $this->delegate(new ReflectionContainer());
32 11
    }
33
34 5
    public function dispatch($job, $params = [])
35
    {
36 5
        return $this->get(Runner::class)->dispatch($job, $params);
37
    }
38
39 11
    public function get($alias, array $args = [])
40
    {
41 11
        if (!$this->hasShared($alias, true) && 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...
42
            $spaceName = $this->get(Mapper::class)
43
                ->getPlugin(Annotation::class)
44
                ->getSpaceName($alias);
45
46
            if ($spaceName) {
47
                $instance = $this->get(Mapper::class)->getRepository($spaceName);
48
                $this->share($alias, $instance);
49
            }
50
        }
51 11
        return parent::get($alias, $args);
52
    }
53
}
54