Completed
Push — master ( be00fa...152a7c )
by Beniamin
05:51 queued 02:08
created

TableRegistry   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 37.5%

Importance

Changes 0
Metric Value
dl 0
loc 40
c 0
b 0
f 0
wmc 3
lcom 1
cbo 0
ccs 3
cts 8
cp 0.375
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A registerTable() 0 7 1
A getTableClass() 0 8 2
1
<?php
2
3
namespace Phuria\SQLBuilder;
4
5
/**
6
 * This file is part of Phuria SQL Builder package.
7
 *
8
 * Copyright (c) 2016 Beniamin Jonatan Šimko
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
use Phuria\SQLBuilder\Table\UnknownTable;
15
16
/**
17
 * @author Beniamin Jonatan Šimko <[email protected]>
18
 */
19
class TableRegistry
20
{
21
    /**
22
     * @var array $tables
23
     */
24
    private $tableNameMap = [];
25
26
    /**
27
     * @var array $tableClassMap
28
     */
29
    private $tableClassMap = [];
30
31
    /**
32
     * @param string $tableClass
33
     * @param string $tableName
34
     *
35
     * @return $this
36
     */
37
    public function registerTable($tableClass, $tableName)
38
    {
39
        $this->tableClassMap[$tableClass] = $tableName;
40
        $this->tableNameMap[$tableName] = $tableClass;
41
42
        return $this;
43
    }
44
45
    /**
46
     * @param string $tableName
47
     *
48
     * @return string
49
     */
50 4
    public function getTableClass($tableName)
51
    {
52 4
        if (false === array_key_exists($tableName, $this->tableNameMap)) {
53 4
            return UnknownTable::class;
54
        }
55
56
        return $this->tableNameMap[$tableName];
57
    }
58
}