Passed
Push — main ( 9c348c...0dd59f )
by Andrey
23:53 queued 13:13
created

Boolean::isFalse()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 1
c 1
b 0
f 0
nc 5
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 5
rs 9.6111
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 6
    public function isTrue($value): bool
15
    {
16 6
        return $value === true || $value === 1 || $value === '1' || $value === 'on' || $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 6
    public function isFalse($value): bool
27
    {
28 6
        return $value === false || $value === 0 || $value === '0' || $value === 'off' || $value === 'false';
29
    }
30
31
    /**
32
     * Converts a value to a boolean type.
33
     *
34
     * @param  mixed  $value
35
     *
36
     * @return bool
37
     */
38 2
    public function to($value): bool
39
    {
40 2
        if ($this->isTrue($value)) {
41 2
            return true;
42
        }
43
44 2
        if ($this->isFalse($value)) {
45 2
            return false;
46
        }
47
48 2
        return (bool) $value;
49
    }
50
}
51