Passed
Push — master ( 1ed7a7...991cdb )
by Dallas
15:11 queued 10:18
created

PostgresTextSanitizer::sanitize()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 4
c 1
b 0
f 1
dl 0
loc 10
ccs 4
cts 5
cp 0.8
rs 10
cc 2
nc 2
nop 1
crap 2.032
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Umbrellio\Postgres\Helpers;
6
7
class PostgresTextSanitizer
8
{
9
    /**
10
     * Удаляет запрещённые/опасные символы из строки для PostgreSQL.
11
     *
12
     * Удаляются:
13
     * - \x00 (нулевой байт)
14
     * - управляющие символы ASCII от \x01 до \x1F, кроме \x09, \x0A, \x0D
15
     */
16 2
    public static function sanitize(?string $input): ?string
17
    {
18 2
        if ($input === null) {
19
            return null;
20
        }
21
22
        // Удаляем управляющие символы, кроме: табуляция (\x09), \n (\x0A), \r (\x0D)
23 2
        $input = preg_replace('/[\x00-\x08\x0B\x0C\x0E-\x1F]/u', '', $input);
24
25 2
        return $input;
26
    }
27
}
28