Constructor   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
B creating() 0 19 7
1
<?php
2
/**
3
 * Objects constructor
4
 * User: moyo
5
 * Date: 12/10/2017
6
 * Time: 10:37 AM
7
 */
8
9
namespace Carno\Container\Injection;
10
11
trait Constructor
12
{
13
    /**
14
     * @param string $class
15
     * @param mixed ...$args
16
     * @return object|mixed
17
     */
18
    private function creating(string $class, ...$args)
19
    {
20
        $ref = new Reflection($this, $class, $args);
21
22
        if ($ref->hasConstructor()) {
23
            foreach ($params = $ref->getConstructParams() as $idx => $val) {
24
                $val instanceof Dependency && $params[$idx] = $val->object();
25
            }
26
        }
27
28
        $object = new $class(...($params ?? []));
29
30
        if ($ref->hasProperties()) {
31
            foreach ($ref->getPropertyInjects() as $name => $target) {
32
                $target instanceof Dependency && $ref->setProperty($object, $name, $target->object());
33
            }
34
        }
35
36
        return $object;
37
    }
38
}
39