Min::__invoke()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 7
cts 7
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 7
nc 3
nop 3
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\Sanitize;
10
11
/**
12
 *
13
 * Sanitizes to minimum value if value is less than min.
14
 *
15
 * @package Aura.Filter
16
 *
17
 */
18
class Min
19
{
20
    /**
21
     *
22
     * Sanitizes to minimum value if value is less than min.
23
     *
24
     * @param object $subject The subject to be filtered.
25
     *
26
     * @param string $field The subject field name.
27
     *
28
     * @param int $min The minimum value.
29
     *
30
     * @return bool True if the value was sanitized, false if not.
31
     *
32
     */
33 7
    public function __invoke($subject, $field, $min)
34
    {
35 7
        $value = $subject->$field;
36 7
        if (! is_scalar($value)) {
37 1
            return false;
38
        }
39 6
        if ($value < $min) {
40 3
            $subject->$field = $min;
41
        }
42 6
        return true;
43
    }
44
}
45