Passed
Push — master ( 59b394...acff9b )
by Mauro
09:10 queued 07:14
created

EquivTextToBase64   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A transform() 0 17 4
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * @author domenico [email protected] / [email protected]
5
 * Date: 13/05/19
6
 * Time: 19.37
7
 *
8
 */
9
10
namespace Matecat\SubFiltering\Filters;
11
12
use Matecat\SubFiltering\Commons\AbstractHandler;
13
14
class EquivTextToBase64 extends AbstractHandler {
15
16 73
    public function transform( $segment ) {
17
18
        // extract equiv-text attribute
19 73
        preg_match_all('/equiv-text=\"(.*?)\"/', $segment, $equiv_tags);
20
21 73
        if(!empty($equiv_tags[0])){
22 40
            foreach ($equiv_tags[0] as $index => $equiv_tag){
23 40
                $tag = $equiv_tags[1][$index];
24
25 40
                if (strpos($tag, "base64:") === false) {
26 1
                    $b = base64_encode($tag);
27 1
                    $segment = str_replace($equiv_tags[$index], 'equiv-text="base64:'.$b.'"', $segment);
28
                }
29
            }
30
        }
31
32 73
        return $segment;
33
    }
34
}
35