Failed Conditions
Push — master ( c242cc...25b015 )
by Niels
02:36 queued 17s
created

NumbersSegment::sanitizeValue()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 9.4285
cc 3
eloc 4
nc 2
nop 1
crap 3
1
<?php
2
3
/*
4
 * Semver
5
 * (c) Omines Internetbureau B.V. - www.omines.nl
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Omines\Semver\Version;
12
13
use Omines\Semver\Exception\SemverException;
14
15
/**
16
 * NumbersSegment
17
 *
18
 * @author Niels Keurentjes <[email protected]>
19
 */
20
class NumbersSegment extends AbstractSegment
21
{
22
    /**
23
     * @param int $first
24
     * @param int $second
25
     * @return int|double
26
     */
27 104
    protected function compareElements($first, $second)
28
    {
29 104
        return $first - $second;
30
    }
31
32
    /**
33
     * @param mixed $value
34
     * @return int
35
     */
36 97
    protected function sanitizeValue($value)
37
    {
38 97
        if (is_int($value) || ctype_digit($value)) {
39 97
            return (int) $value;
40
        }
41 1
        throw SemverException::format('"%s" is not a numeric version segment value', $value);
42
    }
43
}
44