Passed
Push — master ( 163405...503637 )
by George
02:38
created

BooleanValidator::formatDefault()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
cc 2
eloc 3
nc 2
nop 0
crap 2
1
<?php
2
namespace JsonTable\Validate\Format;
3
4
use \JsonTable\Validate\AbstractFormatValidator;
5
6
/**
7
 * Lexical boolean validator.
8
 *
9
 * @package JSON table
10
 */
11
class BooleanValidator extends AbstractFormatValidator
12
{
13
    /**
14
     * Validate that the input is a valid boolean.
15
     * This accepts:
16
     * 1 and 0
17
     * "1" and "0"
18
     * "on" or "ON" and "off" or "OFF"
19
     * "yes" or "YES" and "no" or "NO"
20
     * true and false
21
     *
22
     * @access  protected
23
     *
24
     * @return  boolean Whether the input is valid.
25
     */
26 1
    protected function formatDefault()
27
    {
28 1
        $value = (is_string($this->input)) ? strtolower($this->input) : $this->input;
29
30 1
        return (null !== filter_var($value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE));
31
    }
32
}
33