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 28
cts 28
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( string $segment ): string {
13
14 86
        $tags = [
15 86
                '\[%s\]',
16 86
                '\[%\d+\$s\]',
17 86
                '\[%\d+\$i\]',
18 86
                '\[%\d+\$s:[a-z_]+\]',
19 86
                '\[%\d+\$i:[a-z_]+\]',
20 86
                '\[%s:[a-z_]+\]',
21 86
                '\[%i\]',
22 86
                '\[%i:[a-z_]+\]',
23 86
                '\[%f\]',
24 86
                '\[%f:[a-z_]+\]',
25 86
                '\[%.\d+f\]',
26 86
                '\[%\d+\$.\d+f\]',
27 86
                '\[%\d+\$.\d+f:[a-z_]+\]',
28 86
                '\[%.\d+f:[a-z_]+\]',
29 86
                '\[%[a-z_]+:\d+%\]',
30 86
        ];
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 2
                    $segment,
42 2
                    1
43 2
            );
44
        }
45
46 86
        return $segment;
47
    }
48
}