SquareSprintf   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 25
c 1
b 0
f 0
dl 0
loc 39
ccs 10
cts 10
cp 1
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A transform() 0 35 2
1
<?php
2
3
namespace Matecat\SubFiltering\Filters;
4
5
use Matecat\SubFiltering\Commons\AbstractHandler;
6
use Matecat\SubFiltering\Enum\CTypeEnum;
7
8
class SquareSprintf extends AbstractHandler {
9
    /**
10
     * @inheritDoc
11
     */
12 86
    public function transform( $segment ) {
13
14
        $tags = [
15 86
            '\[%s\]',
16
            '\[%\d+\$s\]',
17
            '\[%\d+\$i\]',
18
            '\[%\d+\$s:[a-z_]+\]',
19
            '\[%\d+\$i:[a-z_]+\]',
20
            '\[%s:[a-z_]+\]',
21
            '\[%i\]',
22
            '\[%i:[a-z_]+\]',
23
            '\[%f\]',
24
            '\[%f:[a-z_]+\]',
25
            '\[%.\d+f\]',
26
            '\[%\d+\$.\d+f\]',
27
            '\[%\d+\$.\d+f:[a-z_]+\]',
28
            '\[%.\d+f:[a-z_]+\]',
29
            '\[%[a-z_]+:\d+%\]',
30
        ];
31
32 86
        $regex = '/'.implode("|", $tags).'/iu';
33
34 86
        preg_match_all( $regex, $segment, $html, PREG_SET_ORDER );
35
36 86
        foreach ( $html as $pos => $percentSnailVariable ) {
37
38 2
            $segment = preg_replace(
39 2
                    '/' . preg_quote( $percentSnailVariable[ 0 ], '/' ) . '/',
40 2
                    '<ph id="' . $this->getPipeline()->getNextId() . '" ctype="' . CTypeEnum::SQUARE_SPRINTF . '" equiv-text="base64:' . base64_encode( $percentSnailVariable[ 0 ] ) . '"/>',
41
                    $segment,
42 2
                    1
43
            );
44
        }
45
46 86
        return $segment;
47
    }
48
}