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: | |
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: | |
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 toAbsoluteNumber(): Type |
107: | { |
108: | return $this; |
109: | } |
110: | |
111: | public function toFloat(): Type |
112: | { |
113: | return $this; |
114: | } |
115: | |
116: | public function toInteger(): Type |
117: | { |
118: | return new IntegerType(); |
119: | } |
120: | |
121: | public function toString(): Type |
122: | { |
123: | return new IntersectionType([ |
124: | new StringType(), |
125: | new AccessoryUppercaseStringType(), |
126: | new AccessoryNumericStringType(), |
127: | ]); |
128: | } |
129: | |
130: | public function toArray(): Type |
131: | { |
132: | return new ConstantArrayType( |
133: | [new ConstantIntegerType(0)], |
134: | [$this], |
135: | [1], |
136: | isList: TrinaryLogic::createYes(), |
137: | ); |
138: | } |
139: | |
140: | public function toArrayKey(): Type |
141: | { |
142: | return new IntegerType(); |
143: | } |
144: | |
145: | public function toCoercedArgumentType(bool $strictTypes): Type |
146: | { |
147: | if (!$strictTypes) { |
148: | return TypeCombinator::union($this->toInteger(), $this, $this->toString(), $this->toBoolean()); |
149: | } |
150: | |
151: | return $this; |
152: | } |
153: | |
154: | public function isOffsetAccessLegal(): TrinaryLogic |
155: | { |
156: | return TrinaryLogic::createYes(); |
157: | } |
158: | |
159: | public function isNull(): TrinaryLogic |
160: | { |
161: | return TrinaryLogic::createNo(); |
162: | } |
163: | |
164: | public function isConstantValue(): TrinaryLogic |
165: | { |
166: | return TrinaryLogic::createNo(); |
167: | } |
168: | |
169: | public function isConstantScalarValue(): TrinaryLogic |
170: | { |
171: | return TrinaryLogic::createNo(); |
172: | } |
173: | |
174: | public function getConstantScalarTypes(): array |
175: | { |
176: | return []; |
177: | } |
178: | |
179: | public function getConstantScalarValues(): array |
180: | { |
181: | return []; |
182: | } |
183: | |
184: | public function isTrue(): TrinaryLogic |
185: | { |
186: | return TrinaryLogic::createNo(); |
187: | } |
188: | |
189: | public function isFalse(): TrinaryLogic |
190: | { |
191: | return TrinaryLogic::createNo(); |
192: | } |
193: | |
194: | public function isBoolean(): TrinaryLogic |
195: | { |
196: | return TrinaryLogic::createNo(); |
197: | } |
198: | |
199: | public function isFloat(): TrinaryLogic |
200: | { |
201: | return TrinaryLogic::createYes(); |
202: | } |
203: | |
204: | public function isInteger(): TrinaryLogic |
205: | { |
206: | return TrinaryLogic::createNo(); |
207: | } |
208: | |
209: | public function isString(): TrinaryLogic |
210: | { |
211: | return TrinaryLogic::createNo(); |
212: | } |
213: | |
214: | public function isNumericString(): TrinaryLogic |
215: | { |
216: | return TrinaryLogic::createNo(); |
217: | } |
218: | |
219: | public function isNonEmptyString(): TrinaryLogic |
220: | { |
221: | return TrinaryLogic::createNo(); |
222: | } |
223: | |
224: | public function isNonFalsyString(): TrinaryLogic |
225: | { |
226: | return TrinaryLogic::createNo(); |
227: | } |
228: | |
229: | public function isLiteralString(): TrinaryLogic |
230: | { |
231: | return TrinaryLogic::createNo(); |
232: | } |
233: | |
234: | public function isLowercaseString(): TrinaryLogic |
235: | { |
236: | return TrinaryLogic::createNo(); |
237: | } |
238: | |
239: | public function isClassString(): TrinaryLogic |
240: | { |
241: | return TrinaryLogic::createNo(); |
242: | } |
243: | |
244: | public function isUppercaseString(): TrinaryLogic |
245: | { |
246: | return TrinaryLogic::createNo(); |
247: | } |
248: | |
249: | public function getClassStringObjectType(): Type |
250: | { |
251: | return new ErrorType(); |
252: | } |
253: | |
254: | public function getObjectTypeOrClassStringObjectType(): Type |
255: | { |
256: | return new ErrorType(); |
257: | } |
258: | |
259: | public function isVoid(): TrinaryLogic |
260: | { |
261: | return TrinaryLogic::createNo(); |
262: | } |
263: | |
264: | public function isScalar(): TrinaryLogic |
265: | { |
266: | return TrinaryLogic::createYes(); |
267: | } |
268: | |
269: | public function looseCompare(Type $type, PhpVersion $phpVersion): BooleanType |
270: | { |
271: | return new BooleanType(); |
272: | } |
273: | |
274: | public function traverse(callable $cb): Type |
275: | { |
276: | return $this; |
277: | } |
278: | |
279: | public function traverseSimultaneously(Type $right, callable $cb): Type |
280: | { |
281: | return $this; |
282: | } |
283: | |
284: | public function exponentiate(Type $exponent): Type |
285: | { |
286: | return ExponentiateHelper::exponentiate($this, $exponent); |
287: | } |
288: | |
289: | public function toPhpDocNode(): TypeNode |
290: | { |
291: | return new IdentifierTypeNode('float'); |
292: | } |
293: | |
294: | public function getFiniteTypes(): array |
295: | { |
296: | return []; |
297: | } |
298: | |
299: | } |
300: | |