Completed
Push — develop ( e96e2d...4e806c )
by Agel_Nash
06:19
created

helper.php ➔ entities()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
if(!function_exists('createGUID')) {
4
    /**
5
     * create globally unique identifiers (guid)
6
     *
7
     * @return string
8
     */
9
    function createGUID()
10
    {
11
        srand((double)microtime() * 1000000);
12
        $r = rand();
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $r. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
13
        $u = uniqid(getmypid() . $r . (double)microtime() * 1000000, 1);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $u. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
14
        $m = md5($u);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $m. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
15
16
        return $m;
17
    }
18
}
19
20
if(!function_exists('generate_password')) {
21
// Generate password
22
    function generate_password($length = 10)
0 ignored issues
show
Coding Style introduced by
As per coding-style, this function should be in camelCase.

CamelCase (...) is the practice of writing compound words or phrases such that
each word or abbreviation begins with a capital letter.

Learn more about camelCase.

Loading history...
23
    {
24
        $allowable_characters = "abcdefghjkmnpqrstuvxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789";
25
        $ps_len = strlen($allowable_characters);
26
        mt_srand((double)microtime() * 1000000);
27
        $pass = "";
28
        for ($i = 0; $i < $length; $i++) {
29
            $pass .= $allowable_characters[mt_rand(0, $ps_len - 1)];
30
        }
31
32
        return $pass;
33
    }
34
}
35
36
if (! function_exists('entities')) {
37
    /**
38
     * @param  string $string
39
     * @param  string $charset
40
     * @return mixed
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use string.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
41
     */
42
    function entities($string, $charset = 'UTF-8')
43
    {
44
        return htmlentities($string, ENT_COMPAT | ENT_SUBSTITUTE, $charset, false);
45
    }
46
}
47
48
if (! function_exists('get_by_key')) {
49
    /**
50
     * @param mixed $data
51
     * @param string|int $key
52
     * @param mixed $default
53
     * @param Closure $validate
0 ignored issues
show
Documentation introduced by
Should the type for parameter $validate not be Closure|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
54
     * @return mixed
55
     */
56
    function get_by_key($data, $key, $default = null, $validate = null)
0 ignored issues
show
Coding Style introduced by
As per coding-style, this function should be in camelCase.

CamelCase (...) is the practice of writing compound words or phrases such that
each word or abbreviation begins with a capital letter.

Learn more about camelCase.

Loading history...
57
    {
58
        $out = $default;
59
        if (is_array($data) && (is_int($key) || is_string($key)) && $key !== '' && array_key_exists($key, $data)) {
60
            $out = $data[$key];
61
        }
62
        if (! empty($validate) && is_callable($validate)) {
63
            $out = (($validate($out) === true) ? $out : $default);
64
        }
65
        return $out;
66
    }
67
}
68