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

Boolean::parse()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 2
rs 10
c 0
b 0
f 0
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