Completed
Push — master ( 747969...868971 )
by Vincent
02:05
created

helpers.php ➔ array_depth()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 8
nc 4
nop 1
dl 0
loc 16
rs 9.2
c 0
b 0
f 0
1
<?php
2
/*
3
 * BongaTech SMS Client Library for PHP
4
 *
5
 * @copyright Copyright (c) 2017
6
 * @author   Vincent Mosoti <[email protected]>
7
 * @license https://github.com/VMosoti/bongatech-sms/blob/master/LICENSE
8
 */
9
10
use VMosoti\BongaTech\SMS;
11
12
if (!function_exists('sms')) {
13
    /**
14
     * Create a new instance of the SMS class.
15
     *
16
     * @return SMS
17
     */
18
    function sms()
19
    {
20
        return new SMS();
21
    }
22
}
23
24
if (!function_exists('get_balance')) {
25
    /**
26
     * gets the sms units balance.
27
     *
28
     * @return \VMosoti\BongaTech\Response
29
     */
30
    function get_balance()
31
    {
32
        return SMS::getBalance();
33
    }
34
}
35
36
if (!function_exists('array_depth')) {
37
    /**
38
     * returns depth of an array.see http://stackoverflow.com/a/262944.
39
     *
40
     * @param  $array
41
     *
42
     * @return int
43
     */
44
    function array_depth(array $array)
45
    {
46
        $max_depth = 1;
47
48
        foreach ($array as $value) {
49
            if (is_array($value)) {
50
                $depth = array_depth($value) + 1;
51
52
                if ($depth > $max_depth) {
53
                    $max_depth = $depth;
54
                }
55
            }
56
        }
57
58
        return $max_depth;
59
    }
60
}
61