RemoveDangerousChars   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 16
ccs 7
cts 7
cp 1
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A transform() 0 14 1
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
}