Completed
Push — master ( 448360...56edb4 )
by Simone
02:19
created

MethodResolver::resolve()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 13
ccs 8
cts 8
cp 1
rs 9.4285
c 1
b 0
f 0
cc 2
eloc 7
nc 2
nop 1
crap 2
1
<?php
2
3
namespace Sensorario\Container\Resolver;
4
5
use ReflectionClass;
6
use Sensorario\Container\ArgumentBuilder;
7
use Sensorario\Container\Objects\Service;
8
9
class MethodResolver
10
{
11
    private $instances = array();
12
13
    private $builder;
14
15 9
    public function setArgumentBuilder(ArgumentBuilder $builder)
16
    {
17 9
        $this->builder = $builder;
18 9
    }
19
20 2
    public function resolve(Service $service)
21
    {
22 2
        $this->builder->setParams($service->getParams());
23
24 2
        $this->arguments = $this->builder->getArguments();
0 ignored issues
show
Bug introduced by
The property arguments does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
25
26 2
        if (!isset($this->instances[$service->getName()])) {
27 2
            $refObj = new ReflectionClass($service->getClass());
28 2
            $this->instances[$service->getName()] = $refObj->newInstanceArgs($this->arguments);
29 2
        }
30
31 2
        return $this->instances[$service->getName()];
32
    }
33
}
34