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

NumberFormatConverter   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 2
c 1
b 0
f 1
lcom 1
cbo 0
dl 0
loc 43
ccs 2
cts 2
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A convert() 0 4 1
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