NumberFormat   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 0
dl 0
loc 46
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A filter() 0 8 2
1
<?php
2
/**
3
 * Particle.
4
 *
5
 * @link      http://github.com/particle-php for the canonical source repository
6
 * @copyright Copyright (c) 2005-2016 Particle (http://particle-php.com)
7
 * @license   https://github.com/particle-php/Filter/blob/master/LICENSE New BSD License
8
 */
9
namespace Particle\Filter\FilterRule;
10
11
use Particle\Filter\FilterRule;
12
13
/**
14
 * Class NumberFormat
15
 *
16
 * @package Particle\Filter\FilterRule
17
 */
18
class NumberFormat extends FilterRule
19
{
20
    /**
21
     * @var int
22
     */
23
    protected $decimals;
24
25
    /**
26
     * @var string
27
     */
28
    protected $decimalPoint;
29
30
    /**
31
     * @var string
32
     */
33
    protected $thousandSeparator;
34
35
    /**
36
     * Set required params for replacement
37
     *
38
     * @param int    $decimals
39
     * @param string $decimalPoint
40
     * @param string $thousandSeparator
41
     */
42 12
    public function __construct($decimals, $decimalPoint, $thousandSeparator)
43
    {
44 12
        $this->decimals = intval($decimals);
45 12
        $this->decimalPoint = $decimalPoint;
46 12
        $this->thousandSeparator = $thousandSeparator;
47 12
    }
48
49
    /**
50
     * Format the numbers
51
     *
52
     * @param mixed $value
53
     * @return string
54
     */
55 12
    public function filter($value)
56
    {
57 12
        if (empty($value)) {
58 3
            return $value;
59
        }
60
61 9
        return number_format(floatval($value), $this->decimals, $this->decimalPoint, $this->thousandSeparator);
62
    }
63
}
64