Completed
Push — master ( 1ebb0e...4253c0 )
by Joe
02:03
created

BooleanModule   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 64.71%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 11
eloc 18
c 1
b 0
f 0
dl 0
loc 34
ccs 11
cts 17
cp 0.6471
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B makeBoolean() 0 32 11
1
<?php
2
3
namespace PhpWinTools\Support;
4
5
class BooleanModule
6
{
7 1
    public static function makeBoolean($value): bool
8
    {
9 1
        $value = strtolower($value);
10
11 1
        if ($value === true || $value === false) {
12
            return $value;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $value returns the type string which is incompatible with the type-hinted return boolean.
Loading history...
13
        }
14
15 1
        if ($value === 'true') {
16 1
            return true;
17
        }
18
19 1
        if ($value === 'false') {
20 1
            return false;
21
        }
22
23 1
        if ($value === 1 || $value === '1') {
24 1
            return true;
25
        }
26
27 1
        if ($value === 0 || $value === '0') {
28 1
            return false;
29
        }
30
31
        if (is_array($value)) {
0 ignored issues
show
introduced by
The condition is_array($value) is always false.
Loading history...
32
            return !empty($value);
33
        }
34
35
        if (trim($value) !== '') {
36
            return true;
37
        } else {
38
            return false;
39
        }
40
    }
41
}
42