RemoveDangerousChars::transform()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 14
ccs 7
cts 7
cp 1
crap 1
rs 10
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * @author domenico [email protected] / [email protected]
5
 * Date: 13/05/19
6
 * Time: 19.37
7
 *
8
 */
9
10
namespace Matecat\SubFiltering\Filters;
11
12
13
use Matecat\SubFiltering\Commons\AbstractHandler;
14
15
class RemoveDangerousChars extends AbstractHandler {
16
17 16
    public function transform( string $segment ): string {
18
19
        //clean invalid xml entities ( characters with ascii < 32 and different from 0A, 0D and 09
20 16
        $regexpHexEntity = '/&#x(0[0-8BCEF]|1[0-9A-F]|7F);/u';
21
22 16
        $regexpEntity = '/&#(0[0-8]|1[1-2]|1[4-9]|2[0-9]|3[0-1]|127);/u';
23
24
        //remove binary chars in some xliff files
25 16
        $regexpAscii = '/[\x{00}-\x{08}\x{0B}\x{0C}\x{0E}-\x{1F}\x{7F}]/u';
26
27 16
        $segment = preg_replace( $regexpAscii, '', $segment );
28 16
        $segment = preg_replace( $regexpHexEntity, '', $segment );
29
30 16
        return preg_replace( $regexpEntity, '', $segment );
31
32
    }
33
34
}