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

ConstantFloatType::describe()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
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