Passed
Push — master ( 59e1e1...c1229c )
by Ryuichi
03:02
created

Regexp::isValid()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 0
cts 7
cp 0
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 4
nc 3
nop 2
crap 12
1
<?php
2
namespace WebStream\Annotation\Attributes\Ext\ValidateRule;
3
4
/**
5
 * Regexp
6
 * @author Ryuichi TANAKA.
7
 * @since 2015/04/01
8
 * @version 0.4
9
 */
10
class Regexp implements IValidate
11
{
12
    /**
13
     * {@inheritdoc}
14
     */
15
    public function isValid($value, $rule)
16
    {
17
        $isValid = false;
18
        if (preg_match('/^regexp\[(\/.*?\/[a-z]*)\]$/', $rule, $matches)) {
19
            $isValid = $value === null || preg_match($matches[1], $value);
20
        }
21
22
        return $isValid;
23
    }
24
}
25