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

Mailcode_Translator_Syntax_ApacheVelocity::_translateEnd()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
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