Passed
Push — master ( 24f0b7...5fac61 )
by Andy
01:44
created

MoneyNormalizer::format()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 5
ccs 0
cts 3
cp 0
rs 10
cc 1
nc 1
nop 1
crap 2
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