Completed
Push — master ( 2eec4a...b9bd03 )
by Philip
02:02
created

Regexp::validate()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 7
rs 9.2
cc 4
eloc 5
nc 4
nop 2
1
<?php
2
3
/*
4
 * This file is part of the Valdi package.
5
 *
6
 * (c) Philip Lehmann-Böhm <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Valdi\Validator;
13
14
use Valdi\ValidationException;
15
16
/**
17
 * Validator for regular expressions.
18
 */
19
class Regexp implements ValidatorInterface {
20
21
    /**
22
     * {@inheritdoc}
23
     */
24
    public function validate($value, array $parameters) {
25
        if (count($parameters) !== 1) {
26
            throw new ValidationException('"regexp" expects one parameter.');
27
        }
28
        return $value === '' || $value === null ||
29
            @preg_match($parameters[0], $value) === 1;
30
    }
31
}
32