Passed
Push — master ( 37f3ab...68213e )
by Mike
02:44
created

DependencyProvider   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Test Coverage

Coverage 85.71%

Importance

Changes 0
Metric Value
wmc 6
eloc 10
dl 0
loc 68
ccs 12
cts 14
cp 0.8571
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getConfig() 0 3 1
A __construct() 0 3 1
A set() 0 5 1
A register() 0 3 1
A getLocator() 0 3 1
A get() 0 3 1
1
<?php
2
declare(strict_types=1);
3
4
5
namespace Xervice\Core\Dependency;
6
7
8
use Xervice\Core\Config\ConfigInterface;
9
use Xervice\Core\Dependency\Provider\ProviderInterface;
10
use Xervice\Core\Locator\Locator;
11
12
13
class DependencyProvider implements DependencyProviderInterface
14
{
15
    /**
16
     * @var \Xervice\Core\Config\ConfigInterface
17
     */
18
    private $config;
19
20
    /**
21
     * @var callable[]
22
     */
23
    private $container;
24
25
    /**
26
     * DependencyProvider constructor.
27
     *
28
     * @param \Xervice\Core\Config\ConfigInterface $config
29
     */
30 7
    public function __construct(ConfigInterface $config)
31
    {
32 7
        $this->config = $config;
33 7
    }
34
35
36
    /**
37
     * @param string $name
38
     * @param callable $function
39
     *
40
     * @return \Xervice\Core\Dependency\DependencyProviderInterface
41
     */
42 1
    public function set(string $name, callable $function): DependencyProviderInterface
43
    {
44 1
        $this->container[$name] = $function;
45
46 1
        return $this;
47
    }
48
49
    /**
50
     * @param string $name
51
     *
52
     * @return mixed
53
     */
54 1
    public function get(string $name)
55
    {
56 1
        return $this->container[$name]();
57
    }
58
59
    /**
60
     * @return \Xervice\Core\Config\ConfigInterface
61
     */
62 1
    public function getConfig(): ConfigInterface
63
    {
64 1
        return $this->config;
65
    }
66
67
    /**
68
     * @return \Generated\Ide\LocatorAutoComplete|\Xervice\Core\Locator\Locator
0 ignored issues
show
Bug introduced by
The type Generated\Ide\LocatorAutoComplete was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
69
     */
70
    public function getLocator(): Locator
71
    {
72
        return Locator::getInstance();
73
    }
74
75
    /**
76
     * @param \Xervice\Core\Dependency\Provider\ProviderInterface $provider
77
     */
78 1
    public function register(ProviderInterface $provider): void
79
    {
80 1
        $provider->handleDependencies($this);
81 1
    }
82
83
84
}