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

IntScalar::isBuiltin()   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 IntScalar
18
 */
19
final class IntScalar extends ScalarDefinition
20
{
21
    /**
22
     * @var string
23
     */
24
    public const TYPE_NAME = 'Int';
25
26
    /**
27
     * @var string
28
     */
29
    public const TYPE_DESCRIPTION = 'A signed 32‐bit integer.';
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 int
45
     * @throws TypeConflictException
46
     */
47
    public function parse($value): int
48
    {
49
        if (! \is_scalar($value)) {
50
            throw new TypeConflictException(\sprintf('Could not parse %s type', \gettype($value)));
51
        }
52
53
        return (int)parent::parse($value);
54
    }
55
56
    /**
57
     * @param mixed $value
58
     * @return int
59
     * @throws TypeConflictException
60
     */
61
    public function serialize($value): int
62
    {
63
        if (! \is_scalar($value)) {
64
            throw new TypeConflictException(\sprintf('Could not serialize %s type', \gettype($value)));
65
        }
66
67
        return (int)parent::serialize($value);
68
    }
69
70
    /**
71
     * @return int
72
     */
73
    public function getLine(): int
74
    {
75
        return 4;
76
    }
77
78
    /**
79
     * @return bool
80
     */
81
    public function isBuiltin(): bool
82
    {
83
        return true;
84
    }
85
}
86