Passed
Push — master ( 1b5df6...213867 )
by Sebastian
13:22
created

Mailcode_Translator_Syntax_ApacheVelocity   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 21
c 1
b 0
f 0
dl 0
loc 36
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A filterRegexString() 0 27 2
1
<?php
2
/**
3
 * File containing the {@see Mailcode_Translator_Syntax_ApacheVelocity} class.
4
 *
5
 * @package Mailcode
6
 * @subpackage Translator
7
 * @see Mailcode_Translator_Syntax_ApacheVelocity
8
 */
9
10
declare(strict_types=1);
11
12
namespace Mailcode;
13
14
/**
15
 * Abstract base class for apache velocity command translation classes. 
16
 *
17
 * @package Mailcode
18
 * @subpackage Translator
19
 * @author Sebastian Mordziol <[email protected]>
20
 */
21
abstract class Mailcode_Translator_Syntax_ApacheVelocity extends Mailcode_Translator_Command
22
{
23
   /**
24
    * Filters the string for use in an Apache Velocity (Java)
25
    * regex string: escapes all special characters.
26
    * 
27
    * @param string $string
28
    * @return string
29
    */
30
    protected function filterRegexString(string $string) : string
31
    {
32
        $escape = array(
33
            '\\',
34
            '?',
35
            '.',
36
            '[',
37
            ']',
38
            '|',
39
            '{',
40
            '}',
41
            '$',
42
            '*',
43
            '^',
44
            '+',
45
            '<',
46
            '>',
47
            '(',
48
            ')'
49
        );
50
        
51
        foreach($escape as $char)
52
        {
53
            $string = str_replace($char, '\\'.$char, $string);
54
        }
55
        
56
        return $string;
57
    }
58
}
59