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