AliasRegistry::add()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
dl 0
loc 4
rs 10
c 1
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
namespace Kir\MySQL\Tools;
4
5
use RuntimeException;
6
7
class AliasRegistry {
8
	/** @var string[] */
9
	private array $aliases = [];
10
11
	/**
12
	 * @param string $alias
13
	 * @param string $string
14
	 * @return $this
15
	 */
16
	public function add(string $alias, string $string): self {
17
		$this->aliases[$alias] = $string;
18
19
		return $this;
20
	}
21
22
	/**
23
	 * @param string $alias
24
	 * @return string
25
	 */
26
	public function get(string $alias): string {
27
		if(!array_key_exists($alias, $this->aliases)) {
28
			throw new RuntimeException("Alias not found: {$alias}");
29
		}
30
31
		return $this->aliases[$alias];
32
	}
33
34
	/**
35
	 * @return string[]
36
	 */
37
	public function getAll(): array {
38
		return $this->aliases;
39
	}
40
}
41