StrlenBetween::__invoke()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 6
cts 6
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 6
nc 3
nop 4
crap 3
1
<?php
2
/**
3
 *
4
 * This file is part of Aura for PHP.
5
 *
6
 * @license http://opensource.org/licenses/bsd-license.php BSD
7
 *
8
 */
9
namespace Aura\Filter\Rule\Validate;
10
11
use Aura\Filter\Rule\AbstractStrlen;
12
13
/**
14
 *
15
 * Validates that the length of the value is within a given range.
16
 *
17
 * @package Aura.Filter
18
 *
19
 */
20
class StrlenBetween extends AbstractStrlen
21
{
22
    /**
23
     *
24
     * Validates that the length of the value is within a given range.
25
     *
26
     * @param object $subject The subject to be filtered.
27
     *
28
     * @param string $field The subject field name.
29
     *
30
     * @param mixed $min The minimum valid length.
31
     *
32
     * @param mixed $max The maximum valid length.
33
     *
34
     * @return bool True if valid, false if not.
35
     *
36
     */
37 11
    public function __invoke($subject, $field, $min, $max)
38
    {
39 11
        $value = $subject->$field;
40 11
        if (! is_scalar($value)) {
41 1
            return false;
42
        }
43 10
        $len = $this->strlen($value);
44
45 10
        return ($len >= $min && $len <= $max);
46
    }
47
}
48