1: <?php declare(strict_types = 1);
2:
3: namespace PHPStan\Type;
4:
5: use PhpParser\Node\Identifier;
6: use PHPStan\Php\PhpVersion;
7: use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
8: use PHPStan\PhpDocParser\Ast\Type\TypeNode;
9: use PHPStan\TrinaryLogic;
10: use PHPStan\Turbo\ShadowedByTurboExtension;
11: use PHPStan\Type\Accessory\AccessoryNumericStringType;
12: use PHPStan\Type\Accessory\AccessoryUppercaseStringType;
13: use PHPStan\Type\Constant\ConstantArrayType;
14: use PHPStan\Type\Constant\ConstantIntegerType;
15: use PHPStan\Type\Traits\NonArrayTypeTrait;
16: use PHPStan\Type\Traits\NonCallableTypeTrait;
17: use PHPStan\Type\Traits\NonGeneralizableTypeTrait;
18: use PHPStan\Type\Traits\NonGenericTypeTrait;
19: use PHPStan\Type\Traits\NonIterableTypeTrait;
20: use PHPStan\Type\Traits\NonObjectTypeTrait;
21: use PHPStan\Type\Traits\NonOffsetAccessibleTypeTrait;
22: use PHPStan\Type\Traits\NonRemoveableTypeTrait;
23: use PHPStan\Type\Traits\UndecidedBooleanTypeTrait;
24: use PHPStan\Type\Traits\UndecidedComparisonTypeTrait;
25: use function get_class;
26:
27: /** @api */
28: #[InstanceofDeprecated(insteadUse: 'Type::isFloat()')]
29: #[ShadowedByTurboExtension(implementation: __DIR__ . '/../../turbo-ext/src/FloatType.cpp')]
30: class FloatType implements Type
31: {
32:
33: use NonArrayTypeTrait;
34: use NonCallableTypeTrait;
35: use NonIterableTypeTrait;
36: use NonObjectTypeTrait;
37: use UndecidedBooleanTypeTrait;
38: use UndecidedComparisonTypeTrait;
39: use NonGenericTypeTrait;
40: use NonOffsetAccessibleTypeTrait;
41: use NonRemoveableTypeTrait;
42: use NonGeneralizableTypeTrait;
43:
44: /** @api */
45: public function __construct()
46: {
47: }
48:
49: public function getReferencedClasses(): array
50: {
51: return [];
52: }
53:
54: public function getObjectClassNames(): array
55: {
56: return [];
57: }
58:
59: public function getObjectClassReflections(): array
60: {
61: return [];
62: }
63:
64: public function getConstantStrings(): array
65: {
66: return [];
67: }
68:
69: public function accepts(Type $type, bool $strictTypes): AcceptsResult
70: {
71: if ($type instanceof self || $type->isInteger()->yes()) {
72: return AcceptsResult::createYes();
73: }
74:
75: if ($type instanceof CompoundType) {
76: return $type->isAcceptedBy($this, $strictTypes);
77: }
78:
79: return AcceptsResult::createNo();
80: }
81:
82: public function isSuperTypeOf(Type $type): IsSuperTypeOfResult
83: {
84: if ($type instanceof self) {
85: return IsSuperTypeOfResult::createYes();
86: }
87:
88: if ($type instanceof CompoundType) {
89: return $type->isSubTypeOf($this);
90: }
91:
92: return IsSuperTypeOfResult::createNo();
93: }
94:
95: public function equals(Type $type): bool
96: {
97: return get_class($type) === static::class;
98: }
99:
100: public function describe(VerbosityLevel $level): string
101: {
102: return 'float';
103: }
104:
105: public function toNumber(): Type
106: {
107: return $this;
108: }
109:
110: public function toBitwiseNotType(): Type
111: {
112: return new IntegerType();
113: }
114:
115: public function toAbsoluteNumber(): Type
116: {
117: return $this;
118: }
119:
120: public function toFloat(): Type
121: {
122: return $this;
123: }
124:
125: public function toInteger(): Type
126: {
127: return new IntegerType();
128: }
129:
130: public function toString(): Type
131: {
132: return new IntersectionType([
133: new StringType(),
134: new AccessoryUppercaseStringType(),
135: new AccessoryNumericStringType(),
136: ]);
137: }
138:
139: public function toArray(): Type
140: {
141: return new ConstantArrayType(
142: [new ConstantIntegerType(0)],
143: [$this],
144: [1],
145: isList: TrinaryLogic::createYes(),
146: );
147: }
148:
149: public function toArrayKey(): Type
150: {
151: return new IntegerType();
152: }
153:
154: public function toCoercedArgumentType(bool $strictTypes): Type
155: {
156: if (!$strictTypes) {
157: return TypeCombinator::union($this->toInteger(), $this, $this->toString(), $this->toBoolean());
158: }
159:
160: return $this;
161: }
162:
163: public function isOffsetAccessLegal(): TrinaryLogic
164: {
165: return TrinaryLogic::createYes();
166: }
167:
168: public function isNull(): TrinaryLogic
169: {
170: return TrinaryLogic::createNo();
171: }
172:
173: public function isConstantValue(): TrinaryLogic
174: {
175: return TrinaryLogic::createNo();
176: }
177:
178: public function isConstantScalarValue(): TrinaryLogic
179: {
180: return TrinaryLogic::createNo();
181: }
182:
183: public function getConstantScalarTypes(): array
184: {
185: return [];
186: }
187:
188: public function getConstantScalarValues(): array
189: {
190: return [];
191: }
192:
193: public function isTrue(): TrinaryLogic
194: {
195: return TrinaryLogic::createNo();
196: }
197:
198: public function isFalse(): TrinaryLogic
199: {
200: return TrinaryLogic::createNo();
201: }
202:
203: public function isBoolean(): TrinaryLogic
204: {
205: return TrinaryLogic::createNo();
206: }
207:
208: public function isFloat(): TrinaryLogic
209: {
210: return TrinaryLogic::createYes();
211: }
212:
213: public function isInteger(): TrinaryLogic
214: {
215: return TrinaryLogic::createNo();
216: }
217:
218: public function isString(): TrinaryLogic
219: {
220: return TrinaryLogic::createNo();
221: }
222:
223: public function isNumericString(): TrinaryLogic
224: {
225: return TrinaryLogic::createNo();
226: }
227:
228: public function isDecimalIntegerString(): TrinaryLogic
229: {
230: return TrinaryLogic::createNo();
231: }
232:
233: public function isNonEmptyString(): TrinaryLogic
234: {
235: return TrinaryLogic::createNo();
236: }
237:
238: public function isNonFalsyString(): TrinaryLogic
239: {
240: return TrinaryLogic::createNo();
241: }
242:
243: public function isLiteralString(): TrinaryLogic
244: {
245: return TrinaryLogic::createNo();
246: }
247:
248: public function isLowercaseString(): TrinaryLogic
249: {
250: return TrinaryLogic::createNo();
251: }
252:
253: public function isClassString(): TrinaryLogic
254: {
255: return TrinaryLogic::createNo();
256: }
257:
258: public function isUppercaseString(): TrinaryLogic
259: {
260: return TrinaryLogic::createNo();
261: }
262:
263: public function getClassStringObjectType(): Type
264: {
265: return new ErrorType();
266: }
267:
268: public function getObjectTypeOrClassStringObjectType(): Type
269: {
270: return new ErrorType();
271: }
272:
273: public function isVoid(): TrinaryLogic
274: {
275: return TrinaryLogic::createNo();
276: }
277:
278: public function isScalar(): TrinaryLogic
279: {
280: return TrinaryLogic::createYes();
281: }
282:
283: public function looseCompare(Type $type, PhpVersion $phpVersion): BooleanType
284: {
285: return new BooleanType();
286: }
287:
288: public function traverse(callable $cb): Type
289: {
290: return $this;
291: }
292:
293: public function traverseSimultaneously(Type $right, callable $cb): Type
294: {
295: return $this;
296: }
297:
298: public function exponentiate(Type $exponent): Type
299: {
300: return ExponentiateHelper::exponentiate($this, $exponent);
301: }
302:
303: public function toPhpDocNode(): TypeNode
304: {
305: return new IdentifierTypeNode('float');
306: }
307:
308: public function toNativePhpTypeNode(NativeTypePosition $position)
309: {
310: return $position->isScalarAllowed() ? new Identifier('float') : null;
311: }
312:
313: public function getFiniteTypes(): array
314: {
315: return [];
316: }
317:
318: public function hasTemplateOrLateResolvableType(): bool
319: {
320: return false;
321: }
322:
323: }
324: