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

Is::boolean()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 1
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 2
rs 10
1
<?php
2
3
namespace Helldar\Support\Helpers;
4
5
use Exception;
6
use Helldar\Support\Facades\Helpers\Arr as ArrHelper;
7
use Helldar\Support\Facades\Helpers\Boolean as BooleanHelper;
8
use Helldar\Support\Facades\Helpers\Instance as InstanceHelper;
9
use Helldar\Support\Facades\Helpers\Reflection as ReflectionHelper;
10
use Helldar\Support\Facades\Helpers\Str as StrHelper;
11
use ReflectionClass;
12
use Throwable;
13
14
final class Is
15
{
16
    /**
17
     * Determines if the value is empty.
18
     *
19
     * @param  mixed  $value
20
     *
21
     * @return bool
22
     */
23 4
    public function isEmpty($value): bool
24
    {
25 4
        if (is_numeric($value) || is_bool($value)) {
26 4
            return false;
27
        }
28
29 4
        return empty($value) || StrHelper::isEmpty($value) || ArrHelper::isEmpty($value);
30
    }
31
32
    /**
33
     * Determines if the value is doesn't empty.
34
     *
35
     * @param  mixed  $value
36
     *
37
     * @return bool
38
     */
39 2
    public function doesntEmpty($value): bool
40
    {
41 2
        return ! $this->isEmpty($value);
42
    }
43
44
    /**
45
     * Finds whether a variable is an object.
46
     *
47
     * @param  mixed  $value
48
     *
49
     * @return bool
50
     */
51 100
    public function object($value): bool
52
    {
53 100
        return is_object($value);
54
    }
55
56
    /**
57
     * Find whether the type of a variable is string.
58
     *
59
     * @param  mixed  $value
60
     *
61
     * @return bool
62
     */
63 94
    public function string($value): bool
64
    {
65 94
        return is_string($value);
66
    }
67
68
    /**
69
     * Determines if a value is boolean.
70
     *
71
     * @param  mixed  $value
72
     *
73
     * @return bool
74
     */
75 2
    public function boolean($value): bool
76
    {
77 2
        return BooleanHelper::isTrue($value) || BooleanHelper::isFalse($value);
78
    }
79
80
    /**
81
     * Find whether the type of a variable is interface.
82
     *
83
     * @param  mixed  $value
84
     *
85
     * @return bool
86
     */
87 2
    public function contract($value): bool
88
    {
89 2
        if (is_string($value)) {
90 2
            $class = InstanceHelper::classname($value);
91
92 2
            return ! empty($class) && interface_exists($class);
93
        }
94
95 2
        return ReflectionHelper::resolve($value)->isInterface();
96
    }
97
98
    /**
99
     * Find whether the type of a variable is exception.
100
     *
101
     * @param  mixed  $value
102
     *
103
     * @return bool
104
     */
105 2
    public function error($value): bool
106
    {
107 2
        return InstanceHelper::of($value, [Exception::class, Throwable::class]);
108
    }
109
110
    /**
111
     * Find whether the type of a variable is ReflectionClass.
112
     *
113
     * @param  mixed  $value
114
     *
115
     * @return bool
116
     */
117 44
    public function reflectionClass($value): bool
118
    {
119 44
        return $value instanceof ReflectionClass;
120
    }
121
}
122