Completed
Push — master ( 44b4d6...c54f73 )
by WEBEWEB
06:15
created

FloatHelper   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 20
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A parseString() 0 9 3
1
<?php
2
3
/**
4
 * This file is part of the core-library package.
5
 *
6
 * (c) 2018 WEBEWEB
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 WBW\Library\Core\Helper\Argument;
13
14
use WBW\Library\Core\Exception\Argument\FloatArgumentException;
15
16
/**
17
 * Float helper.
18
 *
19
 * @author webeweb <https://github.com/webeweb/>
20
 * @package WBW\Library\Core\Helper\Argument
21
 */
22
class FloatHelper {
23
24
    /**
25
     * Parse a string.
26
     *
27
     * @param string $value The string value.
28
     * @return float Returns the float represented by the string value.
29
     * @throws FloatArgumentException Throws a float argument exception if the string value does not represent a float.
30
     */
31
    public static function parseString($value) {
32
        if (null === $value) {
33
            return null;
34
        }
35
        if (0 === preg_match("/^[0-9]{1,}(\.[0-9]{0,})?$/", $value)) {
36
            throw new FloatArgumentException($value);
37
        }
38
        return floatval($value);
39
    }
40
41
}
42