Passed
Push — master ( 180e44...b50543 )
by Radu
02:21
created

MysqlDatabaseTrait::escapeIdentifier()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php
2
namespace WebServCo\Framework\Traits;
3
4
trait MysqlDatabaseTrait
5
{
6
    public function escapeIdentifier($string)
7
    {
8
        return '`' . str_replace('`', '``', $string) . '`';
9
    }
10
11
    public function escapeTableName($string)
12
    {
13
        $parts = explode('.', $string);
14
        if (!empty($parts[1])) {
15
            return sprintf(
16
                '%s.%s',
17
                $this->escapeIdentifier($parts[0]),
18
                $this->escapeIdentifier($parts[1]),
19
            );
20
        }
21
        return $this->escapeIdentifier($parts[0]);
22
    }
23
}
24