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

FormatDollars::execute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 2
c 1
b 0
f 0
nc 2
nop 4
dl 0
loc 10
rs 10
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