Completed
Pull Request — master (#18)
by Propa
09:42
created

helpers.php ➔ number()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 2
dl 0
loc 8
ccs 3
cts 3
cp 1
crap 2
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 \Propaganistas\LaravelIntl\Country|string
9
     */
10
    function country($countryCode = null)
11
    {
12 6
        if (is_null($countryCode)) {
13 6
            return app('intl.country');
14
        }
15
16 3
        return app('intl.country')->name($countryCode);
17
    }
18
}
19
20
if (! function_exists('currency')) {
21
    /**
22
     * Get a localized currency or currency amount.
23
     *
24
     * @return \Propaganistas\LaravelIntl\Currency|string
25
     */
26
    function currency()
27
    {
28 6
        $arguments = func_get_args();
29
30 6
        if (count($arguments) === 0) {
31 6
            return app('intl.currency');
32
        }
33
34 3
        if (count($arguments) > 0 && is_numeric($arguments[0])) {
35 3
            return app('intl.currency')->format(...$arguments);
36
        }
37
38 3
        return 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 6
        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 \Propaganistas\LaravelIntl\Language|string
62
     */
63
    function language($langCode = null)
64
    {
65 6
        if (is_null($langCode)) {
66 6
            return app('intl.language');
67
        }
68
69 3
        return app('intl.language')->name($langCode);
70
    }
71
}
72
73
if (! function_exists('number')) {
74
    /**
75
     * Get a formatted localized number.
76
     *
77
     * @param null $number
78
     * @param array $options
79
     * @return \Propaganistas\LaravelIntl\Number|string
80
     */
81
    function number($number = null, $options = [])
82
    {
83 6
        if (is_null($number)) {
84 6
            return app('intl.number');
85
        }
86
87 3
        return app('intl.number')->format($number, $options);
88
    }
89
}
90