Completed
Push — master ( d9b797...3abea4 )
by Propa
06:42
created

helpers.php ➔ number()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3.0416

Importance

Changes 0
Metric Value
cc 3
eloc 6
nc 3
nop 1
dl 0
loc 12
ccs 5
cts 6
cp 0.8333
crap 3.0416
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
if (!function_exists('country')) {
4
    /**
5
     * Get a localized country name.
6
     *
7
     * @param string|null $countryCode
8
     * @return \CommerceGuys\Intl\Country\Country|string
9
     */
10
    function country($countryCode = null)
11
    {
12 5
        if (is_null($countryCode)) {
13 4
            return app('intl.country');
14
        }
15
16 2
        return app('intl.country')->name($countryCode);
17 2
    }
18
}
19
20
if (!function_exists('currency')) {
21
    /**
22
     * Get a localized currency or currency amount.
23
     *
24
     * @return \CommerceGuys\Intl\Currency\Currency|string
25
     */
26
    function currency()
27
    {
28 8
        $arguments = func_get_args();
29
30 8
        if (count($arguments) === 0) {
31 6
            return app('intl.currency');
32
        }
33
34 2
        if (count($arguments) > 0 && is_numeric($arguments[0])) {
35 2
            return call_user_func_array([app('intl.currency'), 'format'], $arguments);
36
        }
37
38 2
        return call_user_func_array([app('intl.currency'), 'name'], $arguments);
39
    }
40
}
41
42
if (!function_exists('carbon')) {
43
    /**
44
     * Get a localized Carbon instance.
45
     *
46
     * @param  string              $time
47
     * @param  string|DateTimeZone $timezone
48
     * @return \Jenssegers\Date\Date|string
49
     */
50
    function carbon($time = null, $timezone = null)
51
    {
52 4
        return app('intl.date')->make($time, $timezone);
53
    }
54
}
55
56
if (!function_exists('language')) {
57
    /**
58
     * Get a localized language name.
59
     *
60
     * @param string|null $langCode
61
     * @return \CommerceGuys\Intl\Language\Language|string
62
     */
63
    function language($langCode = null)
64
    {
65 6
        if (is_null($langCode)) {
66 4
            return app('intl.language');
67
        }
68
69 2
        return app('intl.language')->name($langCode);
70 2
    }
71
}
72
73
if (!function_exists('number')) {
74
    /**
75
     * Get a localized value.
76
     *
77
     * @param int|float|string|null $amount
78
     * @return \CommerceGuys\Intl\NumberFormat\NumberFormat|string
79
     */
80
    function number($amount = null)
81
    {
82 5
        if (is_null($amount)) {
83 4
            return app('intl.number');
84
        }
85
86 3
        if (!is_numeric($amount)) {
87
            return app('intl.number')->get($amount);
88
        }
89
90 2
        return app('intl.number')->format($amount);
91
    }
92
}