ServerMetadata::getHost()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 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 server metadata.
13
 */
14
final class ServerMetadata
15
{
16
    /** @var string */
17
    private $host;
18
19
    /** @var DatabaseMetadata[] */
20
    private $databaseMetadataList;
21
22
23
    /**
24
     * @param string $host
25
     * @param DatabaseMetadata[] $databaseMetadataList
26
     */
27 3
    public function __construct(
28
        string $host,
29
        array $databaseMetadataList
30
    ) {
31 3
        $this->host = $host;
32
33 3
        foreach ($databaseMetadataList as $databaseMetadata) {
34 3
            $this->databaseMetadataList[$databaseMetadata->getDatabaseName()] = $databaseMetadata;
35
        }
36 3
    }
37
38 1
    public function getHost(): string
39
    {
40 1
        return $this->host;
41
    }
42
43
    /**
44
     * Returns all database metadata.
45
     *
46
     * @return DatabaseMetadata[]
47
     */
48 1
    public function getAllDatabaseMetadata(): array
49
    {
50 1
        return $this->databaseMetadataList;
51
    }
52
53
    /**
54
     * Returns database metadata for the specified database.
55
     */
56 2
    public function getDatabaseMetadata(string $databaseName): DatabaseMetadata
57
    {
58 2
        if (!array_key_exists($databaseName, $this->databaseMetadataList)) {
59 1
            throw new \RuntimeException('Server "' . $this->host . '" doesn\'t contain database "' . $databaseName . '"');
60
        }
61
62 1
        return $this->databaseMetadataList[$databaseName];
63
    }
64
}