RestorePlaceHoldersToXLIFFLtGt   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 3
c 1
b 0
f 0
dl 0
loc 16
ccs 3
cts 3
cp 1
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A transform() 0 6 1
1
<?php
2
/**
3
 * This file contains the RestorePlaceHoldersToXLIFFLtGt class, which is responsible
4
 * for restoring escaped greater-than and less-than characters in a string.
5
 */
6
7
namespace Matecat\SubFiltering\Filters;
8
9
use Matecat\SubFiltering\Commons\AbstractHandler;
10
use Matecat\SubFiltering\Enum\ConstantEnum;
11
12
/**
13
 * A filter handler that restores placeholders for angle brackets back to their original characters.
14
 *
15
 * This handler is a crucial part of the reverse transformation process. During sub-filtering,
16
 * literal '<' and '>' characters are often converted into safe placeholders (e.g., '##LESSTHAN##'
17
 * and '##GREATERTHAN##') to prevent them from being misinterpreted as XML/HTML tags.
18
 *
19
 * This class reverses that process, ensuring that the final output string has the correct
20
 * angle bracket characters, making it suitable for rendering or final storage where
21
 * these characters are expected.
22
 */
23
class RestorePlaceHoldersToXLIFFLtGt extends AbstractHandler {
24
25
    /**
26
     * Replaces temporary placeholders for less-than and greater-than characters with
27
     * their original '<' and '>' equivalents.
28
     *
29
     * @param string $segment The input string containing placeholders.
30
     *
31
     * @return string The transformed string with '<' and '>' characters restored.
32
     */
33 97
    public function transform( string $segment ): string {
34
        // Replace the less-than placeholder (e.g., '##LESSTHAN##') with the actual '<' character.
35 97
        $segment = str_replace( ConstantEnum::LTPLACEHOLDER, "<", $segment );
36
37
        // Replace the greater-than placeholder (e.g., '##GREATERTHAN##') with the actual '>' character.
38 97
        return str_replace( ConstantEnum::GTPLACEHOLDER, ">", $segment );
39
    }
40
}