Completed
Pull Request — master (#21)
by Florian
03:30 queued 01:13
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
12
namespace Plum\Plum\Converter;
13
14
/**
15
 * NumberFormatConverter.
16
 *
17
 * @author    Florian Eckerstorfer
18
 * @copyright 2014-2016 Florian Eckerstorfer
19
 */
20
class NumberFormatConverter implements ConverterInterface
21
{
22
    /**
23
     * @var int
24
     */
25
    protected $decimals;
26
27
    /**
28
     * @var string
29
     */
30
    protected $decimalPoint;
31
32
    /**
33
     * @var string
34
     */
35
    protected $thousandsSeparator;
36
37
    /**
38
     * NumberFormatConverter constructor.
39
     *
40
     * @param int    $decimals
41
     * @param string $decimalPoint
42
     * @param string $thousandsSeparator
43
     *
44
     * @codeCoverageIgnore
45
     */
46
    public function __construct($decimals = 0, $decimalPoint = '.', $thousandsSeparator = ',')
47
    {
48
        $this->decimals           = $decimals;
49
        $this->decimalPoint       = $decimalPoint;
50
        $this->thousandsSeparator = $thousandsSeparator;
51
    }
52
53
    /**
54
     * @param mixed $item
55
     *
56
     * @return mixed
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use string.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
57
     */
58 2
    public function convert($item)
59
    {
60 2
        return number_format($item, $this->decimals, $this->decimalPoint, $this->thousandsSeparator);
61
    }
62
}
63