Integer::__invoke()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 5
nc 3
nop 2
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
/**
12
 *
13
 * Validates that the value represents an integer.
14
 *
15
 * @package Aura.Filter
16
 *
17
 */
18
class Integer
19
{
20
    /**
21
     *
22
     * Validates that the value represents an integer.
23
     *
24
     * @param object $subject The subject to be filtered.
25
     *
26
     * @param string $field The subject field name.
27
     *
28
     * @return bool True if valid, false if not.
29
     *
30
     */
31 11
    public function __invoke($subject, $field)
32
    {
33 11
        $value = $subject->$field;
34
35 11
        if (is_int($value)) {
36 2
            return true;
37
        }
38
39
        // otherwise, must be numeric, and must be same as when cast to int
40 9
        return is_numeric($value) && $value == (int) $value;
41
    }
42
}
43