AliasRegistry::add()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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