Completed
Push — master ( 7ea003...b9e0e5 )
by Dmitry
03:31
created

Application   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 87.1%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 11
c 1
b 0
f 0
lcom 1
cbo 3
dl 0
loc 55
ccs 27
cts 31
cp 0.871
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 20 2
B dispatch() 0 16 5
A get() 0 14 4
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 15
    public function __construct(string $root)
14
    {
15 15
        parent::__construct();
16
17 15
        $fs = new Filesystem($this, $root);
18
19 15
        $this->share(Application::class, $this);
20 15
        $this->share(Container::class, $this);
21 15
        $this->share(Filesystem::class, $fs);
22
23 15
        $this->addServiceProvider(Provider\CoreProvider::class);
24 15
        $this->addServiceProvider(Provider\ServiceProvider::class);
25 15
        $this->addServiceProvider(Provider\TarantoolProvider::class);
26
27 15
        foreach ($fs->listClasses('Provider') as $provider) {
28 15
            $this->addServiceProvider($provider);
29
        }
30
31 15
        $this->delegate(new ReflectionContainer());
32 15
    }
33
34 8
    public function dispatch(string $job, array $params = [], string $service = null)
35
    {
36 8
        if ($service) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $service of type null|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
37
            if ($this->get(Service::class)->getName() == $service) {
38
                $service = null;
39
            }
40
        }
41
42 8
        $runner = $this->get(Runner::class);
43 8
        if (!$service && $runner->hasJob($job)) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $service of type null|string is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
44 8
            return $runner->dispatch($job, $params);
45
        }
46
47
        $dispatcher = $this->get(Dispatcher::class);
48
        return $dispatcher->dispatch($job, $params, $service);
49
    }
50
51 15
    public function get($alias, array $args = [])
52
    {
53 15
        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...
54 1
            $spaceName = $this->get(Mapper::class)
55 1
                ->getPlugin(Annotation::class)
56 1
                ->getRepositorySpaceName($alias);
57
58 1
            if ($spaceName) {
59 1
                $instance = $this->get(Mapper::class)->getRepository($spaceName);
60 1
                $this->share($alias, $instance);
61
            }
62
        }
63 15
        return parent::get($alias, $args);
64
    }
65
}
66