NumericComparator   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A compare() 0 4 1
A supports() 0 4 3
1
<?php
2
3
namespace PHPExtra\Sorter\Comparator;
4
5
/**
6
 * Compare numbers. Uses BCMath's bccomp function. Default scale is set to 10.
7
 *
8
 * @author Jacek Kobus <[email protected]>
9
 */
10
class NumericComparator implements ComparatorInterface
11
{
12
    /**
13
     * @var int
14
     */
15
    private $scale;
16
17
    /**
18
     * @param int $scale
19
     */
20 20
    function __construct($scale = 10)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
21
    {
22 20
        $this->scale = $scale;
23 20
    }
24
25
    /**
26
     * {@inheritdoc}
27
     */
28 14
    public function compare($a, $b)
29
    {
30 14
        return bccomp((string)$a, (string)$b, $this->scale);
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36 5
    public function supports($value)
37
    {
38 5
        return is_numeric($value) || is_int($value) || is_float($value);
39
    }
40
}