Test Failed
Push — master ( d820d2...d59132 )
by Kirill
02:27
created

FloatScalar   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 25%

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 2
dl 0
loc 67
ccs 4
cts 16
cp 0.25
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A parse() 0 8 2
A serialize() 0 8 2
A getLine() 0 4 1
A isBuiltin() 0 4 1
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
     * BooleanScalar constructor.
33
     * @param Document $document
34
     */
35 9
    public function __construct(Document $document)
36
    {
37 9
        parent::__construct($document, self::TYPE_NAME);
38
39 9
        $this->withDescription(self::TYPE_DESCRIPTION);
40 9
    }
41
42
    /**
43
     * @param mixed $value
44
     * @return float
45
     * @throws TypeConflictException
46
     */
47
    public function parse($value): float
48
    {
49
        if (! \is_scalar($value)) {
50
            throw new TypeConflictException(\sprintf('Could not parse %s type', \gettype($value)));
51
        }
52
53
        return (float)parent::parse($value);
54
    }
55
56
    /**
57
     * @param mixed $value
58
     * @return float
59
     * @throws TypeConflictException
60
     */
61
    public function serialize($value): float
62
    {
63
        if (! \is_scalar($value)) {
64
            throw new TypeConflictException(\sprintf('Could not serialize %s type', \gettype($value)));
65
        }
66
67
        return (float)parent::serialize($value);
68
    }
69
70
    /**
71
     * @return int
72
     */
73
    public function getLine(): int
74
    {
75
        return 8;
76
    }
77
78
    /**
79
     * @return bool
80
     */
81
    public function isBuiltin(): bool
82
    {
83
        return true;
84
    }
85
}
86