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