Passed
Push — main ( 6c3117...d6ca5c )
by Andrey
01:47
created

Is::doesntEmpty()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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