Completed
Push — master ( 797c9e...b671da )
by Matteo
02:15
created

EscapeInput::realEscapeString()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 12
rs 9.4285
cc 3
eloc 6
nc 2
nop 2
1
<?php
2
3
namespace Mattbit\MysqlCompat\BridgeComponents;
4
5
trait EscapeInput
6
{
7
    public function escapeString($unescapedString)
8
    {
9
        return $this->realEscapeString($unescapedString);
10
    }
11
12
    public function realEscapeString($unescapedString, Connection $linkIdentifier = null)
13
    {
14
        $connection = $this->manager->getOpenConnectionOrFail($linkIdentifier);
1 ignored issue
show
Bug introduced by
The property manager does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
15
16
        $escaped = $connection->quote($unescapedString);
17
        // Hack!
18
        if ($escaped[0] === "'" && $escaped[strlen($escaped)-1] === "'") {
19
            return substr($escaped, 1, -1);
20
        }
21
22
        throw new \Exception("Cannot escape string");
23
    }
24
}
25