Passed
Push — master ( e3c593...b4bdb9 )
by Stephen
01:01
created

FormatDollars   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A execute() 0 10 2
1
<?php
2
3
namespace Sfneal\Currency;
4
5
use Sfneal\Actions\AbstractActionStatic;
6
7
class FormatDollars extends AbstractActionStatic
8
{
9
    /**
10
     * Format a currency float value to a standard format.
11
     *
12
     * @param float $amount
13
     *
14
     * @param int $decimals
15
     * @param string $thousands_sep
16
     * @param bool $dollar_sign_prefix
17
     * @return string
18
     */
19
    public static function execute(float $amount,
20
                                   int $decimals = 2,
21
                                   string $thousands_sep = '',
22
                                   bool $dollar_sign_prefix = false): string
23
    {
24
        // Format $amount
25
        $value = number_format($amount, $decimals, '.', $thousands_sep);
26
27
        // Optionally prefix the value with a dollar sign
28
        return $dollar_sign_prefix ? "$".$value : $value;
29
    }
30
}
31