Passed
Push — master ( 9e2434...486cd6 )
by Ron
01:59
created

MySQLFieldQuoter::quoteField()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 9
rs 10
cc 4
nc 3
nop 1
1
<?php
2
namespace Kir\MySQL\Databases\MySQL;
3
4
use UnexpectedValueException;
5
6
class MySQLFieldQuoter {
7
	/**
8
	 * @param string $field
9
	 * @return string
10
	 */
11
	public static function quoteField(string $field): string {
12
		if(is_numeric($field) || !is_string($field)) {
13
			throw new UnexpectedValueException('Field name is invalid');
14
		}
15
		if(strpos($field, '`') !== false) {
16
			return $field;
17
		}
18
		$parts = explode('.', $field);
19
		return '`'.implode('`.`', $parts).'`';
20
	}
21
}
22