Number::validates()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
ccs 6
cts 6
cp 1
rs 9.4285
cc 3
eloc 5
nc 4
nop 2
crap 3
1
<?php
2
3
/**
4
 * This file is part of slick/validator package
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace Slick\Validator;
11
12
/**
13
 * Number validator
14
 *
15
 * @package Slick\Validator
16
 * @author  Filipe Silva <[email protected]>
17
 */
18
class Number extends AbstractValidator implements ValidatorInterface
19
{
20
21
    /**
22
     * @var array Message templates
23
     */
24
    protected $messageTemplate = 'The value is not a number.';
25
26
    /**
27
     * Returns true if and only if $value meets the validation requirements
28
     *
29
     * The context specified can be used in the validation process so that
30
     * the same value can be valid or invalid depending on that data.
31
     *
32
     * @param mixed $value
33
     * @param array|mixed $context
34
     *
35
     * @return bool
36
     */
37 6
    public function validates($value, $context = [])
38
    {
39 6
        $result = filter_var($value, FILTER_VALIDATE_INT);
40 6
        if (!$result) {
41 4
            $this->addMessage($this->messageTemplate, $value);
42 4
        }
43 6
        return ($result === false) ? false : true;
44
    }
45
}
46