DoubleSquareBrackets   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A transform() 0 16 3
1
<?php
2
3
namespace Matecat\SubFiltering\Filters;
4
5
use Matecat\SubFiltering\Commons\AbstractHandler;
6
use Matecat\SubFiltering\Enum\ConstantEnum;
7
use Matecat\SubFiltering\Enum\CTypeEnum;
8
9
class DoubleSquareBrackets extends AbstractHandler {
10
    /**
11
     * @inheritDoc
12
     */
13 86
    public function transform( string $segment ): string {
14 86
        preg_match_all( '/\[\[[^<>\s]+?\]\]/', $segment, $html, PREG_SET_ORDER );
15 86
        foreach ( $html as $pos => $snail_variable ) {
16
            //check if inside twig variable there is a tag because in this case shouldn't replace the content with PH tag
17 2
            if ( !strstr( $snail_variable[ 0 ], ConstantEnum::GTPLACEHOLDER ) ) {
18
                //replace subsequent elements excluding already encoded
19 2
                $segment = preg_replace(
20 2
                        '/' . preg_quote( $snail_variable[ 0 ], '/' ) . '/',
21 2
                        '<ph id="' . $this->getPipeline()->getNextId() . '" ctype="' . CTypeEnum::DOUBLE_SQUARE_BRACKETS . '" equiv-text="base64:' . base64_encode( $snail_variable[ 0 ] ) . '"/>',
22 2
                        $segment,
23 2
                        1
24 2
                );
25
            }
26
        }
27
28 86
        return $segment;
29
    }
30
}