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

DependencyInjector::execute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 2
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