Objects::isNumber()   A
last analyzed

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
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace __\Traits;
4
5
use __;
6
7
trait Objects
8
{
9
    /**
10
     * Check if give value is array or not.
11
     *
12
     * @usage __::isArray([1, 2, 3]);
13
     *        >> true
14
     *
15
     * @param mixed $value
16
     *
17
     * @return bool
18
     */
19 11
    public static function isArray($value = null): bool
20
    {
21 11
        return is_array($value);
22
    }
23
24
    /**
25
     * Check if give value is function or not.
26
     *
27
     * @usage __::isFunction(function ($a) { return $a + 2; });
28
     *        >> true
29
     *
30
     * @param mixed $value
31
     *
32
     * @return bool
33
     */
34 1
    public static function isFunction($value = null): bool
35
    {
36 1
        return is_callable($value);
37
    }
38
39
    /**
40
     * Check if give value is null or not.
41
     *
42
     * @usage __::isNull(null);
43
     *        >> true
44
     *
45
     * @param mixed $value
46
     *
47
     * @return bool
48
     */
49 16
    public static function isNull($value = null): bool
50
    {
51 16
        return is_null($value);
52
    }
53
54
55
    /**
56
     * Check if give value is number or not.
57
     *
58
     * @usage __::isNumber(123);
59
     *        >> true
60
     *
61
     * @param mixed $value
62
     *
63
     * @return bool
64
     */
65 1
    public static function isNumber($value = null): bool
66
    {
67 1
        return is_numeric($value);
68
    }
69
70
    /**
71
     * Check if give value is object or not.
72
     *
73
     * @usage __::isObject('fred');
74
     *        >> false
75
     *
76
     * @param mixed $value
77
     *
78
     * @return bool
79
     */
80 21
    public static function isObject($value = null): bool
81
    {
82 21
        return is_object($value);
83
    }
84
85
    /**
86
     * Check if give value is string or not.
87
     *
88
     * @usage __::isString('fred');
89
     *        >> true
90
     *
91
     * @param mixed $value
92
     *
93
     * @return bool
94
     */
95 1
    public static function isString($value = null): bool
96
    {
97 1
        return is_string($value);
98
    }
99
100
    /**
101
     * Check if the object is a collection. A collection is either an array or an object.
102
     *
103
     * @param mixed $value
104
     *
105
     * @return bool
106
     */
107 4
    public static function isCollection($value): bool
108
    {
109 4
        return __::isArray($value) || __::isObject($value);
110
    }
111
}
112