EscapeInput   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A escapeString() 0 4 1
A realEscapeString() 0 12 3
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