AbstractFilter::isValid()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 2
nc 2
nop 2
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 2
rs 10
c 0
b 0
f 0
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
/**
15
 * Base validator for PHPs filter_var function.
16
 */
17
abstract class AbstractFilter implements ValidatorInterface
18
{
19
20
    /**
21
     * Gets the filter to use within the validation.
22
     * See http://php.net/manual/de/filter.filters.validate.php .
23
     *
24
     * @return string - the filter to use
25
     */
26
    abstract protected function getFilter();
27
28
    /**
29
     * Gets the flags to use within the validation.
30
     * See http://php.net/manual/de/filter.filters.validate.php .
31
     *
32
     * @return string|null - the flags to use
33
     */
34 15
    protected function getFlags()
35
    {
36 15
        return null;
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42 17
    public function isValid($value, array $parameters)
43
    {
44 17
        return in_array($value, ['', null], true) ||
45 17
            filter_var($value, $this->getFilter(), $this->getFlags()) !== false;
0 ignored issues
show
Bug introduced by
$this->getFlags() of type null is incompatible with the type array|integer expected by parameter $options of filter_var(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

45
            filter_var($value, $this->getFilter(), /** @scrutinizer ignore-type */ $this->getFlags()) !== false;
Loading history...
46
    }
47
}
48