FromLayer2ToRawXML   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A transform() 0 15 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * @author domenico [email protected] / [email protected]
5
 * Date: 05/11/18
6
 * Time: 18.47
7
 *
8
 */
9
10
namespace Matecat\SubFiltering\Filters;
11
12
use Matecat\SubFiltering\Commons\AbstractHandler;
13
use Matecat\SubFiltering\Enum\ConstantEnum;
14
use Matecat\SubFiltering\Utils\Utils;
15
16
/**
17
 * Class FromLayer2ToRawXML
18
 * Same as EncodeToRawXML but from strings coming from layer 2
19
 *
20
 * @package SubFiltering\Filters
21
 */
22
class FromLayer2ToRawXML extends AbstractHandler {
23
24 38
    public function transform( string $segment ): string {
25
26
        //normal control characters must be converted to entities
27 38
        $segment = str_replace(
28 38
                [ "\r\n", "\r", "\n", "\t", "", ],
29 38
                [
30 38
                        '&#13;&#10;',
31 38
                        '&#13;',
32 38
                        '&#10;',
33 38
                        '&#09;',
34 38
                        '&#157;',
35 38
                ], $segment );
36
37
        // now convert the real &nbsp;
38 38
        return str_replace( ConstantEnum::nbspPlaceholder, Utils::unicode2chr( 0Xa0 ), $segment );
39
40
    }
41
42
}