PercentSnail   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A transform() 0 21 2
1
<?php
2
3
namespace Matecat\SubFiltering\Filters;
4
5
use Matecat\SubFiltering\Commons\AbstractHandler;
6
use Matecat\SubFiltering\Enum\CTypeEnum;
7
use Matecat\SubFiltering\Filters\Sprintf\SprintfLocker;
8
9
class PercentSnail extends AbstractHandler {
10
    /**
11
     * @inheritDoc
12
     */
13 13
    public function transform( $segment ) {
14
15 13
        $sprintfLocker = new SprintfLocker( $this->pipeline->getSource(), $this->pipeline->getTarget() );
16
17
        //placeholding
18 13
        $segment = $sprintfLocker->lock( $segment );
19
20 13
        preg_match_all( '/%@/', $segment, $html, PREG_SET_ORDER );
21 13
        foreach ( $html as $pos => $percentSnailVariable ) {
22
23 1
            $segment = preg_replace(
24 1
                    '/' . preg_quote( $percentSnailVariable[ 0 ], '/' ) . '/',
25 1
                    '<ph id="' . $this->getPipeline()->getNextId() . '" ctype="' . CTypeEnum::PERCENT_SNAILS . '" equiv-text="base64:' . base64_encode( $percentSnailVariable[ 0 ] ) . '"/>',
26
                    $segment,
27 1
                    1
28
            );
29
        }
30
31 13
        $segment = $sprintfLocker->unlock( $segment );
32
33 13
        return $segment;
34
    }
35
}