EquivTextToBase64::transform()   A
last analyzed

Complexity

Conditions 4
Paths 2

Size

Total Lines 17
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 8
nc 2
nop 1
dl 0
loc 17
ccs 9
cts 9
cp 1
crap 4
rs 10
c 1
b 0
f 0
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 88
    public function transform( string $segment ): string {
17
18
        // extract equiv-text attribute
19 88
        preg_match_all( '/equiv-text=\"(.*?)\"/', $segment, $equiv_tags );
20
21 88
        if ( !empty( $equiv_tags[ 0 ] ) ) {
22 53
            foreach ( $equiv_tags[ 0 ] as $index => $equiv_tag ) {
23 53
                $tag = $equiv_tags[ 1 ][ $index ];
24
25 53
                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 88
        return $segment;
33
    }
34
}
35