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