StandardXEquivTextToMateCatCustomPH::transform()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 7
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 13
ccs 10
cts 10
cp 1
crap 2
rs 10
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * @author domenico [email protected] / [email protected]
5
 * Date: 11/01/19
6
 * Time: 15.11
7
 *
8
 */
9
10
namespace Matecat\SubFiltering\Filters;
11
12
use Matecat\SubFiltering\Commons\AbstractHandler;
13
use Matecat\SubFiltering\Enum\CTypeEnum;
14
15
class StandardXEquivTextToMateCatCustomPH extends AbstractHandler {
16
17 88
    public function transform( string $segment ): string {
18
19 88
        preg_match_all( '|<x[^>]*?equiv-text="([^"]*?)"[^>]*?/>|', $segment, $xTags, PREG_SET_ORDER );
20 88
        foreach ( $xTags as $group ) {
21 5
            $segment = preg_replace(
22 5
                    '/' . preg_quote( $group[ 0 ], '/' ) . '/',
23 5
                    '<ph id="' . $this->getPipeline()->getNextId() . '" ctype="' . CTypeEnum::ORIGINAL_X . '" x-orig="' . base64_encode( $group[ 0 ] ) . '" equiv-text="base64:' . base64_encode( $group[ 1 ] ) . '"/>',
24 5
                    $segment,
25 5
                    1
26 5
            );
27
        }
28
29 88
        return $segment;
30
31
    }
32
33
34
}
35
36
37