DriverContainer   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 37
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A getFactory() 0 13 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PHPFastCGI\FastCGIDaemon\Driver;
6
7
use PHPFastCGI\FastCGIDaemon\DaemonFactoryInterface;
8
9
final class DriverContainer implements DriverContainerInterface
10
{
11
    /**
12
     * @var array
13
     */
14
    private $drivers;
15
16
    /**
17
     * Constructor.
18
     */
19
    public function __construct()
20
    {
21
        $this->drivers = [
22
            'userland' => [
23
                'object'    => null,
24
                'classPath' => 'PHPFastCGI\FastCGIDaemon\Driver\Userland\UserlandDaemonFactory',
25
            ],
26
        ];
27
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function getFactory(string $driver): DaemonFactoryInterface
33
    {
34
        if (!isset($this->drivers[$driver])) {
35
            throw new \InvalidArgumentException('Unknown driver: '.$driver);
36
        }
37
38
        if (null === $this->drivers[$driver]['object']) {
39
            $class = $this->drivers[$driver]['classPath'];
40
            $this->drivers[$driver]['object'] = new $class();
41
        }
42
43
        return $this->drivers[$driver]['object'];
44
    }
45
}
46