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

BooleanModule::makeBoolean()   B

Complexity

Conditions 11
Paths 8

Size

Total Lines 32
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 16.3179

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
c 1
b 0
f 0
dl 0
loc 32
ccs 11
cts 17
cp 0.6471
rs 7.3166
cc 11
nc 8
nop 1
crap 16.3179

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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