Passed
Pull Request — master (#1)
by Zeeshan
01:41
created

Utilities::identity()   A

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