Utilities::identity()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 2
nc 2
nop 0
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace __\Traits;
4
5
trait Utilities
6
{
7
    /**
8
     * Check if the value is valid email.
9
     *
10
     * @usage __::isEmail('[email protected]');
11
     *        >> true
12
     *
13
     * @param string $value
14
     *
15
     * @return bool
16
     */
17 1
    public static function isEmail(string $value = null): bool
18
    {
19 1
        return filter_var($value, FILTER_VALIDATE_EMAIL) != false;
20
    }
21
22
    /**
23
     * Alis to original time() function which return current time.
24
     *
25
     * @usage __::now();
26
     *        >> 1417546029
27
     *
28
     * @return mixed
29
     */
30 1
    public static function now()
31
    {
32 1
        $now = time();
33
34 1
        return $now;
35
    }
36
37
    /**
38
     * Readable wrapper for strpos()
39
     *
40
     * @usage __::stringContains('waffle', 'wafflecone');
41
     *        >> true
42
     *
43
     * @param  string $needle   Substring to search for
44
     * @param  string $haystack String to search within
45
     * @param  int    $offset   Index of the $haystack we wish to start at
46
     *
47
     * @return bool
48
     */
49 2
    public static function stringContains(string $needle, string $haystack, int $offset = 0): bool
50
    {
51 2
        return strpos($haystack, $needle, $offset) !== false ? true : false;
52
    }
53
54
    /**
55
     * Returns the first argument it receives
56
     *
57
     * @usage __::identity('arg1', 'arg2');
58
     *        >> 'arg1'
59
     *
60
     * @return mixed
61
     */
62 2
    public static function identity()
63
    {
64 2
        $args = func_get_args();
65
66 2
        return isset($args[0]) ? $args[0] : null;
67
    }
68
}
69