Completed
Push — master ( 8f5bc0...179bc9 )
by WEBEWEB
03:06
created

DoubleHelper::parseString()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
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\Argument;
13
14
use WBW\Library\Core\Exception\Argument\DoubleArgumentException;
15
use WBW\Library\Core\Exception\Argument\FloatArgumentException;
16
17
/**
18
 * Double helper.
19
 *
20
 * @author webeweb <https://github.com/webeweb/>
21
 * @package WBW\Library\Core\Argument
22
 */
23
class DoubleHelper {
24
25
    /**
26
     * Determines if a value is a double.
27
     *
28
     * @param mixed $value The value.
29
     * @throws DoubleArgumentException Throws a Double argument exception if the value is not of expected type.
30
     */
31
    public static function isDouble($value) {
32
        if (false === is_double($value)) {
33
            throw new DoubleArgumentException($value);
34
        }
35
    }
36
37
    /**
38
     * Parse a string.
39
     *
40
     * @param string $value The string value.
41
     * @return double Returns the double represented by the string value.
42
     * @throws DoubleArgumentException Throws a double argument exception if the string value does not represent a double.
43
     */
44
    public static function parseString($value) {
45
        try {
46
            return FloatHelper::parseString($value);
47
        } catch (FloatArgumentException $ex) {
48
            throw new DoubleArgumentException($value, $ex);
49
        }
50
    }
51
52
}
53