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

TableRegistry::getTableClass()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 0
Metric Value
dl 0
loc 8
c 0
b 0
f 0
ccs 3
cts 4
cp 0.75
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
crap 2.0625
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
}