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

MySQLFieldQuoter   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 7
c 1
b 0
f 0
dl 0
loc 14
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A quoteField() 0 9 4
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