DatabaseManagerFactory   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getDatabaseManager() 0 13 3
A registerDatabaseManager() 0 3 1
A __construct() 0 3 1
1
<?php
2
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
namespace Db3v4l\Service;
4
5
use Db3v4l\API\Interfaces\DatabaseManager;
6
use OutOfBoundsException;
7
8
class DatabaseManagerFactory
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class DatabaseManagerFactory
Loading history...
9
{
10
    protected $databaseManagers = [];
11
12
    public function __construct(array $databaseManagersList)
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function __construct()
Loading history...
13
    {
14
        $this->databaseManagers = $databaseManagersList;
15
    }
16
17
    public function registerDatabaseManager($vendorName, $managerClass)
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function registerDatabaseManager()
Loading history...
18
    {
19
        $this->databaseManagers[$vendorName] = $managerClass;
20
    }
21
22
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
23
     * @param array $dbConnectionSpec
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
24
     * @return DatabaseManager
0 ignored issues
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
25
     * @throws OutOfBoundsException for unsupported database types
0 ignored issues
show
Coding Style introduced by
Tag @throws cannot be grouped with parameter tags in a doc comment
Loading history...
26
     */
27
    public function getDatabaseManager(array $dbConnectionSpec)
28
    {
29
        if (!isset($dbConnectionSpec['vendor'])) {
30
            throw new OutOfBoundsException("Unspecified database type  (miss 'vendor' key in definition)");
31
        }
32
33
        $vendor = $dbConnectionSpec['vendor'];
34
        if (isset($this->databaseManagers[$vendor])) {
35
            $class = $this->databaseManagers[$vendor];
36
            return new $class($dbConnectionSpec);
37
        }
38
39
        throw new OutOfBoundsException("Unsupported database type '$vendor'");
40
    }
41
}
42