helpers.php ➔ number()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 2
dl 0
loc 8
ccs 3
cts 3
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
use Illuminate\Support\Facades\Date;
4
5
if (! function_exists('country')) {
6
    /**
7
     * Get a localized country name.
8
     *
9
     * @param string|null $countryCode
10
     * @return \Propaganistas\LaravelIntl\Country|string
11
     */
12
    function country($countryCode = null)
13
    {
14 6
        if (is_null($countryCode)) {
15 6
            return app('intl.country');
16
        }
17
18 3
        return app('intl.country')->name($countryCode);
19
    }
20
}
21
22
if (! function_exists('currency')) {
23
    /**
24
     * Get a localized currency or currency amount.
25
     *
26
     * @return \Propaganistas\LaravelIntl\Currency|string
27
     */
28
    function currency()
29
    {
30 6
        $arguments = func_get_args();
31
32 6
        if (count($arguments) === 0) {
33 6
            return app('intl.currency');
34
        }
35
36 3
        if (count($arguments) > 0 && is_numeric($arguments[0])) {
37 3
            return app('intl.currency')->format(...$arguments);
38
        }
39
40 3
        return app('intl.currency')->name(...$arguments);
41
    }
42
}
43
44
if (! function_exists('carbon')) {
45
    /**
46
     * Get a localized Carbon instance.
47
     *
48
     * @param  string $time
49
     * @param  string|DateTimeZone $timezone
50
     * @return \Illuminate\Support\DateFactory|string
51
     */
52
    function carbon($time = null, $timezone = null)
53
    {
54 3
        return Date::make($time, $timezone);
0 ignored issues
show
Unused Code introduced by
The call to Date::make() has too many arguments starting with $timezone.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
55
    }
56
}
57
58
if (! function_exists('language')) {
59
    /**
60
     * Get a localized language name.
61
     *
62
     * @param string|null $langCode
63
     * @return \Propaganistas\LaravelIntl\Language|string
64
     */
65
    function language($langCode = null)
66
    {
67 6
        if (is_null($langCode)) {
68 6
            return app('intl.language');
69
        }
70
71 3
        return app('intl.language')->name($langCode);
72
    }
73
}
74
75
if (! function_exists('number')) {
76
    /**
77
     * Get a formatted localized number.
78
     *
79
     * @param string|int|float|null $number
80
     * @param array $options
81
     * @return \Propaganistas\LaravelIntl\Number|string
82
     */
83
    function number($number = null, $options = [])
84
    {
85 6
        if (is_null($number)) {
86 6
            return app('intl.number');
87
        }
88
89 3
        return app('intl.number')->format($number, $options);
90
    }
91
}
92