MoneyNormalizer   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
eloc 5
c 0
b 0
f 0
dl 0
loc 18
ccs 0
cts 5
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getNormalizedValue() 0 3 1
A format() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Palmtree\Csv\Normalizer;
6
7
class MoneyNormalizer extends AbstractNormalizer
8
{
9
    private string $moneyFormat = '%.2n';
10
11
    /**
12
     * Sets the format passed to money_format. Defaults to %.2n which formats the number according to the current
13
     * locale's national currency format rounded to 2 decimal places. e.g for en_GB: £1,234.56.
14
     */
15
    public function format(string $moneyFormat): self
16
    {
17
        $this->moneyFormat = $moneyFormat;
18
19
        return $this;
20
    }
21
22
    protected function getNormalizedValue(string $value): string
23
    {
24
        return money_format($this->moneyFormat, (float)$value);
0 ignored issues
show
Bug Best Practice introduced by
The expression return money_format($thi...Format, (double)$value) could return the type null which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
25
    }
26
}
27