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