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

PostgresTextSanitizer   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Test Coverage

Coverage 80%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 2
eloc 5
c 1
b 0
f 1
dl 0
loc 19
ccs 4
cts 5
cp 0.8
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A sanitize() 0 10 2
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