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