Regex::validate()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
/**
3
 * Jaeger
4
 *
5
 * @copyright	Copyright (c) 2015-2016, mithra62
6
 * @link		http://jaeger-app.com
7
 * @version		1.0
8
 * @filesource 	./Regex.php
9
 */
10
namespace JaegerApp;
11
12
use RegexGuard\RegexGuard;
13
14
/**
15
 * Jaeger - Regex Object
16
 *
17
 * Regular Expression execution and validation object
18
 *
19
 * @package Regex
20
 * @author Eric Lamb <[email protected]>
21
 */
22
class Regex
23
{
24
25
    /**
26
     * The Regex library we're using
27
     * 
28
     * @var \RegexGuard\RegexGuard
29
     */
30
    private $instance = null;
31
32
    /**
33
     * Returns an instance of the library
34
     * 
35
     * @return \RegexGuard\RegexGuard
36
     */
37
    private function getInstance()
38
    {
39
        if (is_null($this->instance)) {
40
            $this->instance = \RegexGuard\Factory::getGuard();
41
        }
42
        
43
        return $this->instance;
44
    }
45
46
    /**
47
     * Validates a given regular expression
48
     * 
49
     * @param string $regexp
50
     *            The regular expression to validate
51
     * @return boolean
52
     */
53
    public function validate($regexp)
54
    {
55
        return $this->getInstance()->isRegexValid($regexp);
56
    }
57
58
    /**
59
     * Matches a regular expression
60
     * 
61
     * @param string $pattern
62
     *            The regular expression to execute
63
     * @param string $subject
64
     *            The string to search within
65
     * @return boolean
66
     */
67
    public function match($pattern, $subject)
68
    {
69
        if (! $this->validate($pattern)) {
70
            return false;
71
        }
72
        
73
        return $this->getInstance()->match($pattern, $subject);
74
    }
75
}