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

Regexp   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 13
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
c 1
b 0
f 1
lcom 0
cbo 0
dl 0
loc 13
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A validate() 0 7 4
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