Test Failed
Push — master ( 4bdf7b...97fe68 )
by Kirill
02:15
created

FloatScalar::getLine()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
/**
3
 * This file is part of Railt package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
declare(strict_types=1);
9
10
namespace Railt\Reflection\Stdlib\Scalar;
11
12
use Railt\Reflection\Definition\ScalarDefinition;
13
use Railt\Reflection\Document;
14
use Railt\Reflection\Exception\TypeConflictException;
15
16
/**
17
 * Class FloatScalar
18
 */
19
final class FloatScalar extends ScalarDefinition
20
{
21
    /**
22
     * @var string
23
     */
24
    public const TYPE_NAME = 'Float';
25
26
    /**
27
     * @var string
28
     */
29
    public const TYPE_DESCRIPTION = 'A signed double-precision floating-point value.';
30
31
    /**
32
     * @var int
33
     */
34
    private const DEFINITION_LINE = 8;
35
36
    /**
37
     * BooleanScalar constructor.
38
     * @param Document $document
39
     */
40 9
    public function __construct(Document $document)
41
    {
42 9
        parent::__construct($document, self::TYPE_NAME);
43
44 9
        $this->withDescription(self::TYPE_DESCRIPTION);
45 9
        $this->withLine(self::DEFINITION_LINE);
46 9
    }
47
48
    /**
49
     * @param mixed $value
50
     * @return float
51
     * @throws TypeConflictException
52
     */
53
    public function parse($value): float
54
    {
55
        if (! \is_scalar($value)) {
56
            throw new TypeConflictException(\sprintf('Could not parse %s type', \gettype($value)));
57
        }
58
59
        return (float)parent::parse($value);
60
    }
61
62
    /**
63
     * @param mixed $value
64
     * @return float
65
     * @throws TypeConflictException
66
     */
67
    public function serialize($value): float
68
    {
69
        if (! \is_scalar($value)) {
70
            throw new TypeConflictException(\sprintf('Could not serialize %s type', \gettype($value)));
71
        }
72
73
        return (float)parent::serialize($value);
74
    }
75
76
    /**
77
     * @return bool
78
     */
79
    public function isBuiltin(): bool
80
    {
81
        return true;
82
    }
83
}
84