SmartCounts   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A transform() 0 17 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 SmartCounts extends AbstractHandler {
9
    /**
10
     * @param $segment
11
     *
12
     * @return string
13
     */
14 3
    public function transform( string $segment ): string {
15
        /*
16
         * Examples:
17
         * - [AIRBNB] Reminder: Reply to %{guest}’s inquiry. |||| [AIRBNB] Reminder: Reply to %{guest}’s inquiry.
18
         */
19 3
        preg_match_all( '/(\|\|\|\|)/', $segment, $html, PREG_SET_ORDER );
20 3
        foreach ( $html as $pos => $variable ) {
21
            //replace subsequent elements excluding already encoded
22 2
            $segment = preg_replace(
23 2
                    '/' . preg_quote( $variable[ 0 ], '/' ) . '/',
24 2
                    '<ph id="' . $this->getPipeline()->getNextId() . '" ctype="' . CTypeEnum::SMART_COUNT . '" equiv-text="base64:' . base64_encode( $variable[ 0 ] ) . "\"/>",
25 2
                    $segment,
26 2
                    1
27 2
            );
28
        }
29
30 3
        return $segment;
31
    }
32
}