NumericComparator::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
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
}