Test Failed
Push — master ( aec97b...d7d4d0 )
by Alex
02:17
created

xsBoolean::fixValue()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 3
eloc 6
nc 4
nop 0
1
<?php
2
3
namespace AlgoWeb\xsdTypes;
4
5
/**
6
 * The type xsd:boolean represents logical yes/no values.  The valid values for xsd:boolean are true, false, 0, and 1.
7
 * Values that are capitalized (e.g. TRUE) or abbreviated (e.g. T) are not valid.
8
 * @package AlgoWeb\xsdTypes
9
 */
10
class xsBoolean extends xsAnySimpleType
11
{
12
    /**
13
     * Construct.
14
     *
15
     * @param bool $value
16
     */
17
    public function __construct($value)
18
    {
19
        parent::__construct($value);
20
        $this->setWhiteSpaceFacet('collapse');
21
    }
22
    protected function fixValue()
23
    {
24
        parent::fixValue();
25
        if ($this->value == 0) {
26
            $this->value = false;
27
        }
28
        if ($this->value == 1) {
29
            $this->value = true;
30
        }
31
    }
32
    protected function isOK()
33
    {
34
        if (boolval($this->value) !== $this->value) {
35
            throw new \InvalidArgumentException(
36
                'The provided value for ' . __CLASS__ . ' needs to be a boolean.'
37
            );
38
        }
39
    }
40
}
41