1: | <?php declare(strict_types = 1); |
2: | |
3: | namespace PHPStan\Type; |
4: | |
5: | use PHPStan\Php\PhpVersion; |
6: | use PHPStan\TrinaryLogic; |
7: | use PHPStan\Type\Accessory\AccessoryNumericStringType; |
8: | use PHPStan\Type\Constant\ConstantArrayType; |
9: | use PHPStan\Type\Constant\ConstantIntegerType; |
10: | use PHPStan\Type\Traits\NonArrayTypeTrait; |
11: | use PHPStan\Type\Traits\NonCallableTypeTrait; |
12: | use PHPStan\Type\Traits\NonGeneralizableTypeTrait; |
13: | use PHPStan\Type\Traits\NonGenericTypeTrait; |
14: | use PHPStan\Type\Traits\NonIterableTypeTrait; |
15: | use PHPStan\Type\Traits\NonObjectTypeTrait; |
16: | use PHPStan\Type\Traits\NonOffsetAccessibleTypeTrait; |
17: | use PHPStan\Type\Traits\NonRemoveableTypeTrait; |
18: | use PHPStan\Type\Traits\UndecidedBooleanTypeTrait; |
19: | use PHPStan\Type\Traits\UndecidedComparisonTypeTrait; |
20: | use function get_class; |
21: | |
22: | |
23: | class FloatType implements Type |
24: | { |
25: | |
26: | use NonArrayTypeTrait; |
27: | use NonCallableTypeTrait; |
28: | use NonIterableTypeTrait; |
29: | use NonObjectTypeTrait; |
30: | use UndecidedBooleanTypeTrait; |
31: | use UndecidedComparisonTypeTrait; |
32: | use NonGenericTypeTrait; |
33: | use NonOffsetAccessibleTypeTrait; |
34: | use NonRemoveableTypeTrait; |
35: | use NonGeneralizableTypeTrait; |
36: | |
37: | |
38: | public function __construct() |
39: | { |
40: | } |
41: | |
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): TrinaryLogic |
66: | { |
67: | return $this->acceptsWithReason($type, $strictTypes)->result; |
68: | } |
69: | |
70: | public function acceptsWithReason(Type $type, bool $strictTypes): AcceptsResult |
71: | { |
72: | if ($type instanceof self || $type->isInteger()->yes()) { |
73: | return AcceptsResult::createYes(); |
74: | } |
75: | |
76: | if ($type instanceof CompoundType) { |
77: | return $type->isAcceptedWithReasonBy($this, $strictTypes); |
78: | } |
79: | |
80: | return AcceptsResult::createNo(); |
81: | } |
82: | |
83: | public function isSuperTypeOf(Type $type): TrinaryLogic |
84: | { |
85: | if ($type instanceof self) { |
86: | return TrinaryLogic::createYes(); |
87: | } |
88: | |
89: | if ($type instanceof CompoundType) { |
90: | return $type->isSubTypeOf($this); |
91: | } |
92: | |
93: | return TrinaryLogic::createNo(); |
94: | } |
95: | |
96: | public function equals(Type $type): bool |
97: | { |
98: | return get_class($type) === static::class; |
99: | } |
100: | |
101: | public function describe(VerbosityLevel $level): string |
102: | { |
103: | return 'float'; |
104: | } |
105: | |
106: | public function toNumber(): 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 AccessoryNumericStringType(), |
126: | ]); |
127: | } |
128: | |
129: | public function toArray(): Type |
130: | { |
131: | return new ConstantArrayType( |
132: | [new ConstantIntegerType(0)], |
133: | [$this], |
134: | [1], |
135: | [], |
136: | true, |
137: | ); |
138: | } |
139: | |
140: | public function toArrayKey(): Type |
141: | { |
142: | return new IntegerType(); |
143: | } |
144: | |
145: | public function isNull(): TrinaryLogic |
146: | { |
147: | return TrinaryLogic::createNo(); |
148: | } |
149: | |
150: | public function isConstantValue(): TrinaryLogic |
151: | { |
152: | return TrinaryLogic::createNo(); |
153: | } |
154: | |
155: | public function isConstantScalarValue(): TrinaryLogic |
156: | { |
157: | return TrinaryLogic::createNo(); |
158: | } |
159: | |
160: | public function getConstantScalarTypes(): array |
161: | { |
162: | return []; |
163: | } |
164: | |
165: | public function getConstantScalarValues(): array |
166: | { |
167: | return []; |
168: | } |
169: | |
170: | public function isTrue(): TrinaryLogic |
171: | { |
172: | return TrinaryLogic::createNo(); |
173: | } |
174: | |
175: | public function isFalse(): TrinaryLogic |
176: | { |
177: | return TrinaryLogic::createNo(); |
178: | } |
179: | |
180: | public function isBoolean(): TrinaryLogic |
181: | { |
182: | return TrinaryLogic::createNo(); |
183: | } |
184: | |
185: | public function isFloat(): TrinaryLogic |
186: | { |
187: | return TrinaryLogic::createYes(); |
188: | } |
189: | |
190: | public function isInteger(): TrinaryLogic |
191: | { |
192: | return TrinaryLogic::createNo(); |
193: | } |
194: | |
195: | public function isString(): TrinaryLogic |
196: | { |
197: | return TrinaryLogic::createNo(); |
198: | } |
199: | |
200: | public function isNumericString(): TrinaryLogic |
201: | { |
202: | return TrinaryLogic::createNo(); |
203: | } |
204: | |
205: | public function isNonEmptyString(): TrinaryLogic |
206: | { |
207: | return TrinaryLogic::createNo(); |
208: | } |
209: | |
210: | public function isNonFalsyString(): TrinaryLogic |
211: | { |
212: | return TrinaryLogic::createNo(); |
213: | } |
214: | |
215: | public function isLiteralString(): TrinaryLogic |
216: | { |
217: | return TrinaryLogic::createNo(); |
218: | } |
219: | |
220: | public function isClassStringType(): TrinaryLogic |
221: | { |
222: | return TrinaryLogic::createNo(); |
223: | } |
224: | |
225: | public function getClassStringObjectType(): Type |
226: | { |
227: | return new ErrorType(); |
228: | } |
229: | |
230: | public function getObjectTypeOrClassStringObjectType(): Type |
231: | { |
232: | return new ErrorType(); |
233: | } |
234: | |
235: | public function isVoid(): TrinaryLogic |
236: | { |
237: | return TrinaryLogic::createNo(); |
238: | } |
239: | |
240: | public function isScalar(): TrinaryLogic |
241: | { |
242: | return TrinaryLogic::createYes(); |
243: | } |
244: | |
245: | public function looseCompare(Type $type, PhpVersion $phpVersion): BooleanType |
246: | { |
247: | return new BooleanType(); |
248: | } |
249: | |
250: | public function traverse(callable $cb): Type |
251: | { |
252: | return $this; |
253: | } |
254: | |
255: | public function exponentiate(Type $exponent): Type |
256: | { |
257: | return ExponentiateHelper::exponentiate($this, $exponent); |
258: | } |
259: | |
260: | |
261: | |
262: | |
263: | public static function __set_state(array $properties): Type |
264: | { |
265: | return new self(); |
266: | } |
267: | |
268: | } |
269: | |