EscapeInput::realEscapeString()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 2
nop 2
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
1
<?php
2
3
namespace Mattbit\MysqlCompat\BridgeComponents;
4
5
use Mattbit\MysqlCompat\Connection;
6
7
trait EscapeInput
8
{
9
    public function escapeString($unescapedString)
10
    {
11
        return $this->realEscapeString($unescapedString);
12
    }
13
14
    public function realEscapeString($unescapedString, Connection $linkIdentifier = null)
15
    {
16
        $connection = $this->manager->getOpenConnectionOrFail($linkIdentifier);
17
18
        $escaped = $connection->quote($unescapedString);
19
        // Hack!
20
        if ($escaped[0] === "'" && $escaped[strlen($escaped) - 1] === "'") {
21
            return substr($escaped, 1, -1);
22
        }
23
24
        throw new \Exception('Cannot escape string');
25
    }
26
}
27