| Conditions | 6 |
| Paths | 6 |
| Total Lines | 24 |
| Code Lines | 13 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 13 |
| CRAP Score | 6 |
| Changes | 0 | ||
| 1 | <?php |
||
| 32 | 59 | public function build($class, ...$arguments) |
|
| 33 | { |
||
| 34 | 59 | if (is_object($class)) { |
|
| 35 | 1 | return $class; |
|
| 36 | } |
||
| 37 | |||
| 38 | 58 | if (!class_exists($class)) { |
|
| 39 | 1 | throw new InvalidArgumentException("Unable to build class: $class it does not exist"); |
|
| 40 | } |
||
| 41 | |||
| 42 | 57 | $reflection = new ReflectionClass($class); |
|
| 43 | 57 | $this->log(LogLevel::DEBUG, "Building class: {class}", ['class' => $class]); |
|
| 44 | 57 | $object = $reflection->newInstanceArgs($arguments); |
|
| 45 | |||
| 46 | 57 | if ($object instanceof BuilderAwareInterface) { |
|
| 47 | 1 | $object->setBuilder($this); |
|
| 48 | } |
||
| 49 | |||
| 50 | 57 | if ($this->logger && ($object instanceof LoggerAwareInterface)) { |
|
| 51 | 1 | $object->setLogger($this->logger); |
|
| 52 | } |
||
| 53 | |||
| 54 | 57 | return $object; |
|
| 55 | } |
||
| 56 | } |
||
| 57 |