Completed
Push — master ( 4fa3c4...9bcafd )
by Philip
02:29
created

Contains::isValidComparison()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 7
rs 9.4285
nc 2
cc 2
eloc 5
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
/**
15
 * Validator for strings containing a substring.
16
 */
17
class Contains extends AbstractComparator {
18
19
    /**
20
     * Holds the amount of parameters.
21
     */
22
    protected $amountOfParameters = 2;
23
24
    /**
25
     * Holds the type of the validator.
26
     */
27
    protected $type = 'contains';
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    protected function isValidComparison($value, $parameters) {
33
        if ($parameters[0]) {
34
            $parameters[1] = strtolower($parameters[1]);
35
            $value         = strtolower($value);
36
        }
37
        return strpos($value, $parameters[1]) !== false;
38
    }
39
}
40