AliasReplacer::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 0
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
1
<?php
2
namespace Kir\MySQL\Tools;
3
4
class AliasReplacer {
5
	public function __construct(
6
		private AliasRegistry $aliasRegistry
7
	) {}
8
9
	/**
10
	 * @param string $name
11
	 * @return string
12
	 */
13
	public function replace(string $name): string {
14
		$fn = function($values) {
15
			[, $alias, $part] = $values;
16
			$string = $this->aliasRegistry->get($alias);
17
			return $string.$part;
18
		};
19
		return (string) preg_replace_callback('{^(\\w+)#(\\w+.*)$}', $fn, $name);
20
	}
21
}
22