1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace BestServedCold\PhalueObjects; |
4
|
|
|
|
5
|
|
|
use BestServedCold\PhalueObjects\Contract\Diffable; |
6
|
|
|
use BestServedCold\PhalueObjects\Contract\ValueObject as ValueObjectInterface; |
7
|
|
|
use BestServedCold\PhalueObjects\Contract\VOFloatable; |
8
|
|
|
use BestServedCold\PhalueObjects\Exception\InvalidTypeException; |
9
|
|
|
use BestServedCold\PhalueObjects\VOFloat\Mixin; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class VOFloat |
13
|
|
|
* |
14
|
|
|
* @package BestServedCold\PhalueObjects\Mathematical |
15
|
|
|
* @author Adam Lewis <[email protected]> |
16
|
|
|
* @copyright Copyright (c) 2015 Best Served Cold Media Limited |
17
|
|
|
* @license http://http://opensource.org/licenses/GPL-3.0 GPL License |
18
|
|
|
* @link http://bestservedcold.com |
19
|
|
|
* @since 0.0.1-alpha |
20
|
|
|
* @version 0.0.2-alpha |
21
|
|
|
*/ |
22
|
|
|
class VOFloat extends ValueObject implements \Countable, Diffable, VOFloatable |
23
|
|
|
{ |
24
|
|
|
use Mixin; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @param $value |
28
|
|
|
*/ |
29
|
15 |
|
public function __construct($value) |
30
|
|
|
{ |
31
|
15 |
|
if (!is_float($value) && ! is_int($value)) { |
32
|
|
|
throw new InvalidTypeException($value, [ 'float' ]); |
33
|
|
|
} |
34
|
|
|
|
35
|
15 |
|
parent::__construct($value); |
36
|
15 |
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @return float |
40
|
|
|
*/ |
41
|
13 |
|
public function getValue() |
42
|
|
|
{ |
43
|
13 |
|
return (float) parent::getValue(); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @param float $float |
48
|
|
|
* @return static |
49
|
|
|
*/ |
50
|
8 |
|
public static function fromFloat($float) |
51
|
|
|
{ |
52
|
8 |
|
return new static($float); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @return float |
57
|
|
|
*/ |
58
|
1 |
|
public function toFloat() |
59
|
|
|
{ |
60
|
1 |
|
return $this->getValue(); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @return float |
65
|
|
|
*/ |
66
|
2 |
|
public function count() |
67
|
|
|
{ |
68
|
2 |
|
return $this->getValue(); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @param ValueObjectInterface $object |
73
|
|
|
* @return static |
74
|
|
|
*/ |
75
|
|
|
public function diff(ValueObjectInterface $object) |
76
|
|
|
{ |
77
|
|
|
return new static($this->getValue() - $object->getValue()); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|