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

xsBoolean   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 31
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A fixValue() 0 10 3
A isOK() 0 8 2
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