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