FloatVO   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 0
loc 43
ccs 13
cts 13
cp 1
rs 10
c 2
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 3
A round() 0 4 1
A getValue() 0 6 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