ArgumentBuilder::getArguments()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 20
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 20
ccs 11
cts 11
cp 1
rs 9.2
c 0
b 0
f 0
cc 4
eloc 11
nc 4
nop 0
crap 4
1
<?php
2
3
namespace Sensorario\Container;
4
5
use Psr\Container\ContainerInterface;
6
7
class ArgumentBuilder
8
{
9
    private $container;
10
11
    private $params = [];
12
13 12
    public function setContainer(ContainerInterface $container) : void
14
    {
15 12
        $this->container = $container;
16 12
    }
17
18 3
    public function setParams(array $params) : void
19
    {
20 3
        $this->params = $params;
21 3
    }
22
23 5
    public function getArguments() : array
24
    {
25 5
        $arguments = [];
26
27 5
        if (!$this->container) {
28 1
            throw new \RuntimeException(
29 1
                'Oops! Container is not defined'
30
            );
31
        }
32
33 4
        foreach ($this->params as $param) {
34 3
            $parameter = Objects\Argument::fromString($param);
35
36 3
            $arguments[] = $parameter->isService()
37 3
                ? $this->container->get($param)
38 3
                : $param;
39
        }
40
41 4
        return $arguments;
42
    }
43
}
44