Test Setup Failed
Push — master ( 5d533a...3e433e )
by Herberto
02:34
created

DependencyInjector   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 1
dl 0
loc 27
c 0
b 0
f 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A execute() 0 4 1
1
<?php
2
namespace Hgraca\MicroDI;
3
4
use Hgraca\MicroDI\Exception\CanNotInstantiateDependenciesException;
5
6
final class DependencyInjector
7
{
8
    /**
9
     * @var BuilderInterface
10
     */
11
    private $builder;
12
13
    public function __construct(BuilderInterface $builder)
14
    {
15
        $this->builder = $builder;
16
    }
17
18
    /**
19
     * Executes a callable, building and injecting its dependencies
20
     *
21
     * @param string[]|callable $callable
22
     * @param array             $arguments
23
     *
24
     * @throws CanNotInstantiateDependenciesException
25
     *
26
     * @return mixed
27
     */
28
    public function execute($callable, array $arguments = [])
29
    {
30
        return call_user_func_array($callable, $this->builder->buildDependencies($callable, $arguments));
0 ignored issues
show
Documentation introduced by
$callable is of type callable, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
31
    }
32
}
33