Failed Conditions
Pull Request — master (#256)
by Michael
02:33
created

ConstantFloatType   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
eloc 6
dl 0
loc 28
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getValue() 0 3 1
A __construct() 0 3 1
A describe() 0 3 1
A validate() 0 3 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Annotations\Type\Constant;
6
7
use Doctrine\Annotations\Type\ConstantScalarType;
8
use Doctrine\Annotations\Type\FloatType;
9
use function abs;
10
use function is_float;
11
use function sprintf;
12
13
/**
14
 * @internal
15
 */
16
final class ConstantFloatType extends FloatType implements ConstantScalarType
17
{
18
    public const EPSILON = 1e-15;
19
20
    /** @var float */
21
    private $value;
22
23 3
    public function __construct(float $value)
24
    {
25 3
        $this->value = $value;
26 3
    }
27
28 1
    public function getValue() : float
29
    {
30 1
        return $this->value;
31
    }
32
33 1
    public function describe() : string
34
    {
35 1
        return sprintf('%F', $this->value);
36
    }
37
38
    /**
39
     * @param mixed $value
40
     */
41 1
    public function validate($value) : bool
42
    {
43 1
        return is_float($value) && abs($value - $this->value) < self::EPSILON;
44
    }
45
}
46