InstanceHandler   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 23
rs 10
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 16 5
1
<?php
2
3
namespace Tleckie\Di\Definition\Handler;
4
5
use ReflectionException;
6
use Tleckie\Di\Exception\ContainerException;
7
8
/**
9
 * Class InstanceHandler
10
 *
11
 * @package Tleckie\Di\Handler\Handler
12
 * @author  Teodoro Leckie Westberg <[email protected]>
13
 */
14
class InstanceHandler extends Handler
15
{
16
    /**
17
     * @param $value
18
     * @return mixed
19
     * @throws ContainerException
20
     */
21
    public function handle($value): mixed
22
    {
23
        if (is_array($value) && isset($value['className'])) {
24
            try {
25
                $object = $this->createInstance($value['className'], $value['arguments'] ?? []);
26
                foreach ($value['methods'] ?? [] as $method) {
27
                    $this->callMethod($object, $method['methodName'], $method['arguments'] ?? []);
28
                }
29
            } catch (ReflectionException $exception) {
30
                throw new ContainerException($exception->getMessage());
31
            }
32
33
            return $object;
34
        }
35
36
        return parent::handle($value);
37
    }
38
}
39