ContainerFactory   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 3
c 2
b 0
f 1
lcom 1
cbo 0
dl 0
loc 28
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A build() 0 13 3
1
<?php
2
namespace Autocomplete\Factory;
3
4
use Autocomplete\Contract\Container\ContainerInterface;
5
6
class ContainerFactory
7
{
8
    /**
9
     * @var string $namespace container namespace
10
     */
11
    private $namespace = '\Autocomplete\Container\\';
12
13
    /**
14
     * Build container
15
     *
16
     * @param string $name class name
17
     * @param array $args class arguments
18
     * @return ContainerInterface
19
     */
20
    public function build($name, $args = [])
21
    {
22
        $className = $this->namespace.$name.'\\'.$name;
23
        if ( ! class_exists($className)) {
24
            throw new \Exception('Class: '.$className.' not found.');
25
        }
26
        $container = new \ReflectionClass($className);
27
        $container = $container->newInstanceArgs($args);
28
        if ( ! $container instanceof ContainerInterface) {
29
            throw new \Exception('Bad container implementation');
30
        }
31
        return $container;
32
    }
33
}
34