Passed
Push — main ( 0dd59f...092771 )
by Andrey
11:22 queued 09:59
created

Boolean   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 52
ccs 10
cts 10
cp 1
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A isTrue() 0 3 1
A to() 0 3 1
A isFalse() 0 3 1
A parse() 0 7 2
1
<?php
2
3
namespace Helldar\Support\Helpers;
4
5
final class Boolean
6
{
7
    /**
8
     * Determines if the value is `true`, otherwise it will return `false`.
9
     *
10
     * @param  mixed  $value
11
     *
12
     * @return bool
13
     */
14 3
    public function isTrue($value): bool
15
    {
16 3
        return $this->to($value) === true;
17
    }
18
19
    /**
20
     * Determines if the value is `false`, otherwise it will return `true`.
21
     *
22
     * @param  mixed  $value
23
     *
24
     * @return bool
25
     */
26 3
    public function isFalse($value): bool
27
    {
28 3
        return $this->to($value) === false;
29
    }
30
31
    /**
32
     * Converts a value to a boolean type.
33
     *
34
     * @param  mixed  $value
35
     *
36
     * @return bool
37
     */
38 9
    public function to($value): bool
39
    {
40 9
        return (bool) $this->parse($value);
41
    }
42
43
    /**
44
     * Getting a filtered value in a boolean view.
45
     *
46
     * @param  mixed  $value
47
     *
48
     * @return bool|null
49
     */
50 14
    public function parse($value): ?bool
51
    {
52 14
        if (is_null($value)) {
53 8
            return null;
54
        }
55
56 14
        return filter_var($value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);
57
    }
58
}
59