xsBoolean::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
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
23
    /**
24
     * @return void
25
     */
26
    protected function fixValue()
27
    {
28
        parent::fixValue();
29
30
        $this->value = filter_var($this->value, FILTER_VALIDATE_BOOLEAN, ['options' => [],
31
            'flags' => FILTER_NULL_ON_FAILURE]);
32
        if (null === $this->value) {
33
            throw new \InvalidArgumentException('the value passed to ' . get_class($this) . 'was not a booliean');
34
        }
35
        $this->value = $this->value ? 'true' : 'false';
36
    }
37
38
    /**
39
     * @return void
40
     */
41
    protected function isOK()
42
    {
43
    }
44
}
45