Completed
Push — master ( b54f87...bde51f )
by Beniamin
04:50
created

TableRegistry::getTableClass()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
c 0
b 0
f 0
ccs 4
cts 4
cp 1
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
crap 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 1
    public function registerTable($tableClass, $tableName)
38
    {
39 1
        $this->tableClassMap[$tableClass] = $tableName;
40 1
        $this->tableNameMap[$tableName] = $tableClass;
41
42 1
        return $this;
43
    }
44
45
    /**
46
     * @param string $tableName
47
     *
48
     * @return string
49
     */
50 28
    public function getTableClass($tableName)
51
    {
52 28
        if (false === array_key_exists($tableName, $this->tableNameMap)) {
53 27
            return UnknownTable::class;
54
        }
55
56 1
        return $this->tableNameMap[$tableName];
57
    }
58
}