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

MysqlDatabaseTrait::escapeTableName()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 7
c 0
b 0
f 0
dl 0
loc 11
rs 10
cc 2
nc 2
nop 1
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