Boolean::normalize()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4.016

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 9
cts 10
cp 0.9
rs 9.2
c 0
b 0
f 0
cc 4
eloc 9
nc 4
nop 1
crap 4.016
1
<?php
2
3
namespace Flying\Struct\Property;
4
5
/**
6
 * Structure property with boolean value
7
 */
8
class Boolean extends Property
9
{
10
    /**
11
     * {@inheritdoc}
12
     */
13 161
    protected function normalize(&$value)
14
    {
15 161
        if (!parent::normalize($value)) {
16
            return false;
17
        }
18 161
        if ($value === null) {
19 31
            return true;
20
        }
21 160
        if (!is_scalar($value)) {
22 3
            $value = !empty($value);
23 3
        }
24 160
        $value = (boolean)$value;
25 160
        return true;
26
    }
27
}
28