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