GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

IntlMoneyFormatter   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 42
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A directive() 0 9 1
A handler() 0 10 1
1
<?php
2
3
namespace ProtoneMedia\LaravelMixins\Blade;
4
5
use Illuminate\Support\Facades\Blade;
6
use Money\Currencies\ISOCurrencies;
7
use Money\Formatter\IntlMoneyFormatter as BaseFormatter;
8
use Money\Money;
9
use NumberFormatter;
10
11
class IntlMoneyFormatter
12
{
13
    use BladeDirectiveHelpers;
14
15
    /**
16
     * Calls the format() method on the IntlMoneyFormatter with the given
17
     * amount of cents, currency code and locale.
18
     *
19
     * @param integer $cents
20
     * @param string $code
21
     * @param string $locale
22
     * @return string
23
     */
24
    public static function handler(int $cents, string $code, string $locale): string
25
    {
26
        $formatter = new BaseFormatter(
27
            new NumberFormatter($locale, NumberFormatter::CURRENCY),
28
            new ISOCurrencies
29
        );
30
31
        $money = Money::$code($cents);
32
33
        return $formatter->format($money);
34
    }
35
36
    /**
37
     * Registers a handler for the money formatter.
38
     *
39
     * @param string $name
40
     * @param string $code
41
     * @param string $locale
42
     * @return void
43
     */
44
    public static function directive(string $name = 'money', string $code = 'EUR', string $locale = 'nl_NL')
45
    {
46
        Blade::directive($name, function ($expression) use ($code, $locale) {
47
            $parts = static::parseExpression($expression, [
48
                1 => "'{$code}'",
49
                2 => "'{$locale}'",
50
            ]);
51
52
            return "<?php echo \ProtoneMedia\LaravelMixins\Blade\IntlMoneyFormatter::handler($parts[0], $parts[1], $parts[2]) ?>";
53
        });
54
    }
55
}
56