Completed
Push — master ( 9643f4...a262cd )
by darryl
9s
created

Helpers::formatValue()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 3
eloc 5
nc 2
nop 3
1
<?php namespace Darryldecode\Cart\Helpers;
2
3
/**
4
 * Created by PhpStorm.
5
 * User: darryl
6
 * Date: 1/15/2015
7
 * Time: 8:09 PM
8
 */
9
10
class Helpers {
11
12
    /**
13
     * normalize price
14
     *
15
     * @param $price
16
     * @return float
17
     */
18
    public static function normalizePrice($price)
19
    {
20
        return (is_string($price)) ? floatval($price) : $price;
21
    }
22
23
    /**
24
     * check if array is multi dimensional array
25
     * This will only check the first element of the array if it is still an array
26
     * to decide that it is a multi dimensional, if you want to check the array strictly
27
     * with all on its element, flag the second argument as true
28
     *
29
     * @param $array
30
     * @param bool $recursive
31
     * @return bool
32
     */
33
    public static function isMultiArray($array, $recursive = false)
34
    {
35
        if( $recursive )
36
        {
37
            return (count($array) == count($array, COUNT_RECURSIVE)) ? false : true;
38
        }
39
        else
40
        {
41
            foreach ($array as $k => $v)
42
            {
43
                if (is_array($v))
44
                {
45
                    return true;
46
                }
47
                else
48
                {
49
                    return false;
50
                }
51
            }
52
53
        }
54
    }
55
56
    /**
57
     * check if variable is set and has value, return a default value
58
     *
59
     * @param $var
60
     * @param bool|mixed $default
61
     * @return bool|mixed
62
     */
63
    public static function issetAndHasValueOrAssignDefault(&$var, $default = false)
64
    {
65
        if( (isset($var)) && ($var!='') ) return $var;
66
67
        return $default;
68
    }
69
70
    public static function formatValue($value, $format_numbers, $config)
71
    {
72
        if($format_numbers && $config['format_numbers']) {
73
            return number_format($value, $config['decimals'], $config['dec_point'], $config['thousands_sep']);
74
        } else {
75
            return $value;
76
        }
77
    }
78
}