Completed
Pull Request — master (#21)
by Florian
02:47
created

NumberFormatConverter::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 6
ccs 0
cts 0
cp 0
rs 9.4285
cc 1
eloc 4
nc 1
nop 3
crap 2
1
<?php
2
3
/**
4
 * This file is part of plumphp/plum.
5
 *
6
 * (c) Florian Eckerstorfer <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
namespace Plum\Plum\Converter;
12
13
/**
14
 * NumberFormatConverter.
15
 *
16
 * @author    Florian Eckerstorfer
17
 * @copyright 2014-2016 Florian Eckerstorfer
18
 */
19
class NumberFormatConverter implements ConverterInterface
20
{
21
    /**
22
     * @var int
23
     */
24
    protected $decimals;
25
26
    /**
27
     * @var string
28
     */
29
    protected $decimalPoint;
30
31
    /**
32
     * @var string
33
     */
34
    protected $thousandsSeparator;
35
36
    /**
37
     * NumberFormatConverter constructor.
38
     *
39
     * @param int    $decimals
40
     * @param string $decimalPoint
41
     * @param string $thousandsSeparator
42
     *
43
     * @codeCoverageIgnore
44
     */
45
    public function __construct($decimals = 0, $decimalPoint = '.', $thousandsSeparator = ',')
46
    {
47
        $this->decimals           = $decimals;
48
        $this->decimalPoint       = $decimalPoint;
49
        $this->thousandsSeparator = $thousandsSeparator;
50
    }
51
52
    /**
53
     * @param mixed $item
54
     *
55
     * @return string
56
     */
57 2
    public function convert($item)
58
    {
59 2
        return number_format($item, $this->decimals, $this->decimalPoint, $this->thousandsSeparator);
60
    }
61
}
62