FloatVO::getValue()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 9.4285
c 2
b 0
f 0
cc 2
eloc 4
nc 2
nop 0
crap 2
1
<?php
2
3
namespace BestServedCold\PhalueObjects\Mathematical;
4
5
use BestServedCold\PhalueObjects\Exception\InvalidTypeException;
6
use BestServedCold\PhalueObjects\Mathematical;
7
8
/**
9
 * Class FloatVO
10
 *
11
 * @package   BestServedCold\PhalueObjects\Mathematical
12
 * @author    Adam Lewis <[email protected]>
13
 * @copyright Copyright (c) 2015 Best Served Cold Media Limited
14
 * @license   http://http://opensource.org/licenses/GPL-3.0 GPL License
15
 * @link      http://bestservedcold.com
16
 * @since     0.0.1-alpha
17
 * @version   0.0.2-alpha
18
 */
19
class FloatVO extends Mathematical
20
{
21
    /**
22
     * @var int|null
23
     */
24
    protected $round = null;
25
26
    /**
27
     * @param double $value
28
     */
29 7
    public function __construct($value, $round = null)
30
    {
31 7
        if (!filter_var($value, FILTER_VALIDATE_FLOAT)) {
32 1
            throw new InvalidTypeException($value, [ 'float' ]);
33
        }
34
35 7
        $value = $round ? $this->round($value, $round) : $value;
36
37 7
        $this->round = $round;
38
39 7
        parent::__construct($value);
40 7
    }
41
42
    /**
43
     * @param  $value
44
     * @param  $round
45
     * @return float
46
     */
47 1
    public function round($value, $round)
48
    {
49 1
        return round($value, $round);
50
    }
51
52
    /**
53
     * @return float
54
     */
55 5
    public function getValue()
56
    {
57 5
        return $this->round
58 5
            ? $this->round($this->value, $this->round)
59 5
            : $this->value;
60
    }
61
}
62