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
|
|
|
|