Is::isEmpty()   A
last analyzed

Complexity

Conditions 5
Paths 4

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 5

Importance

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