DatabaseMetadata   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
cbo 1
dl 0
loc 51
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 2
A getDatabaseName() 0 4 1
A getTableMetadata() 0 8 2
A getAllTableMetadata() 0 4 1
1
<?php declare(strict_types=1);
2
3
/**
4
 * @copyright   (c) 2017-present brian ridley
5
 * @author      brian ridley <[email protected]>
6
 * @license     http://opensource.org/licenses/MIT MIT
7
 */
8
9
namespace ptlis\GrepDb\Metadata\MySQL;
10
11
/**
12
 * DTO storing database metadata.
13
 */
14
final class DatabaseMetadata
15
{
16
    /** @var string */
17
    private $databaseName;
18
19
    /** @var TableMetadata[] */
20
    private $tableMetadataList = [];
21
22
23
    /**
24
     * @param string $databaseName
25
     * @param TableMetadata[] $tableMetadataList
26
     */
27 6
    public function __construct(
28
        string $databaseName,
29
        array $tableMetadataList
30
    ) {
31 6
        $this->databaseName = $databaseName;
32
33 6
        foreach ($tableMetadataList as $tableMetadata) {
34 6
            $this->tableMetadataList[$tableMetadata->getTableName()] = $tableMetadata;
35
        }
36 6
    }
37
38 4
    public function getDatabaseName(): string
39
    {
40 4
        return $this->databaseName;
41
    }
42
43
    /**
44
     * Get the metadata for a single table.
45
     */
46 2
    public function getTableMetadata(string $tableName): TableMetadata
47
    {
48 2
        if (!array_key_exists($tableName, $this->tableMetadataList)) {
49 1
            throw new \RuntimeException('Database "' . $this->databaseName . '" doesn\'t contain table "' . $tableName . '"');
50
        }
51
52 1
        return $this->tableMetadataList[$tableName];
53
    }
54
55
    /**
56
     * Get the metadata for all tables.
57
     *
58
     * @return TableMetadata[]
59
     */
60 1
    public function getAllTableMetadata(): array
61
    {
62 1
        return $this->tableMetadataList;
63
    }
64
}