1: <?php declare(strict_types = 1);
2:
3: namespace PHPStan\Type;
4:
5: use PHPStan\TrinaryLogic;
6: use PHPStan\Type\Accessory\AccessoryNumericStringType;
7: use PHPStan\Type\Constant\ConstantArrayType;
8: use PHPStan\Type\Constant\ConstantIntegerType;
9: use PHPStan\Type\Traits\NonArrayTypeTrait;
10: use PHPStan\Type\Traits\NonCallableTypeTrait;
11: use PHPStan\Type\Traits\NonGeneralizableTypeTrait;
12: use PHPStan\Type\Traits\NonGenericTypeTrait;
13: use PHPStan\Type\Traits\NonIterableTypeTrait;
14: use PHPStan\Type\Traits\NonObjectTypeTrait;
15: use PHPStan\Type\Traits\NonOffsetAccessibleTypeTrait;
16: use PHPStan\Type\Traits\NonRemoveableTypeTrait;
17: use PHPStan\Type\Traits\UndecidedBooleanTypeTrait;
18: use PHPStan\Type\Traits\UndecidedComparisonTypeTrait;
19: use function get_class;
20:
21: /** @api */
22: class FloatType implements Type
23: {
24:
25: use NonArrayTypeTrait;
26: use NonCallableTypeTrait;
27: use NonIterableTypeTrait;
28: use NonObjectTypeTrait;
29: use UndecidedBooleanTypeTrait;
30: use UndecidedComparisonTypeTrait;
31: use NonGenericTypeTrait;
32: use NonOffsetAccessibleTypeTrait;
33: use NonRemoveableTypeTrait;
34: use NonGeneralizableTypeTrait;
35:
36: /** @api */
37: public function __construct()
38: {
39: }
40:
41: /**
42: * @return string[]
43: */
44: public function getReferencedClasses(): array
45: {
46: return [];
47: }
48:
49: public function getConstantStrings(): array
50: {
51: return [];
52: }
53:
54: public function accepts(Type $type, bool $strictTypes): TrinaryLogic
55: {
56: if ($type instanceof self || $type->isInteger()->yes()) {
57: return TrinaryLogic::createYes();
58: }
59:
60: if ($type instanceof CompoundType) {
61: return $type->isAcceptedBy($this, $strictTypes);
62: }
63:
64: return TrinaryLogic::createNo();
65: }
66:
67: public function isSuperTypeOf(Type $type): TrinaryLogic
68: {
69: if ($type instanceof self) {
70: return TrinaryLogic::createYes();
71: }
72:
73: if ($type instanceof CompoundType) {
74: return $type->isSubTypeOf($this);
75: }
76:
77: return TrinaryLogic::createNo();
78: }
79:
80: public function equals(Type $type): bool
81: {
82: return get_class($type) === static::class;
83: }
84:
85: public function describe(VerbosityLevel $level): string
86: {
87: return 'float';
88: }
89:
90: public function toNumber(): Type
91: {
92: return $this;
93: }
94:
95: public function toFloat(): Type
96: {
97: return $this;
98: }
99:
100: public function toInteger(): Type
101: {
102: return new IntegerType();
103: }
104:
105: public function toString(): Type
106: {
107: return new IntersectionType([
108: new StringType(),
109: new AccessoryNumericStringType(),
110: ]);
111: }
112:
113: public function toArray(): Type
114: {
115: return new ConstantArrayType(
116: [new ConstantIntegerType(0)],
117: [$this],
118: [1],
119: [],
120: true,
121: );
122: }
123:
124: public function toArrayKey(): Type
125: {
126: return new IntegerType();
127: }
128:
129: public function isNull(): TrinaryLogic
130: {
131: return TrinaryLogic::createNo();
132: }
133:
134: public function isTrue(): TrinaryLogic
135: {
136: return TrinaryLogic::createNo();
137: }
138:
139: public function isFalse(): TrinaryLogic
140: {
141: return TrinaryLogic::createNo();
142: }
143:
144: public function isBoolean(): TrinaryLogic
145: {
146: return TrinaryLogic::createNo();
147: }
148:
149: public function isFloat(): TrinaryLogic
150: {
151: return TrinaryLogic::createYes();
152: }
153:
154: public function isInteger(): TrinaryLogic
155: {
156: return TrinaryLogic::createNo();
157: }
158:
159: public function isString(): TrinaryLogic
160: {
161: return TrinaryLogic::createNo();
162: }
163:
164: public function isNumericString(): TrinaryLogic
165: {
166: return TrinaryLogic::createNo();
167: }
168:
169: public function isNonEmptyString(): TrinaryLogic
170: {
171: return TrinaryLogic::createNo();
172: }
173:
174: public function isNonFalsyString(): TrinaryLogic
175: {
176: return TrinaryLogic::createNo();
177: }
178:
179: public function isLiteralString(): TrinaryLogic
180: {
181: return TrinaryLogic::createNo();
182: }
183:
184: public function isClassStringType(): TrinaryLogic
185: {
186: return TrinaryLogic::createNo();
187: }
188:
189: public function isVoid(): TrinaryLogic
190: {
191: return TrinaryLogic::createNo();
192: }
193:
194: public function isScalar(): TrinaryLogic
195: {
196: return TrinaryLogic::createYes();
197: }
198:
199: public function traverse(callable $cb): Type
200: {
201: return $this;
202: }
203:
204: /**
205: * @param mixed[] $properties
206: */
207: public static function __set_state(array $properties): Type
208: {
209: return new self();
210: }
211:
212: }
213: