1: | <?php declare(strict_types = 1); |
2: | |
3: | namespace PHPStan\Type\Accessory; |
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\AcceptsResult; |
10: | use PHPStan\Type\BooleanType; |
11: | use PHPStan\Type\CompoundType; |
12: | use PHPStan\Type\Constant\ConstantFloatType; |
13: | use PHPStan\Type\Constant\ConstantIntegerType; |
14: | use PHPStan\Type\ErrorType; |
15: | use PHPStan\Type\IntegerRangeType; |
16: | use PHPStan\Type\IntersectionType; |
17: | use PHPStan\Type\IsSuperTypeOfResult; |
18: | use PHPStan\Type\MixedType; |
19: | use PHPStan\Type\Traits\MaybeCallableTypeTrait; |
20: | use PHPStan\Type\Traits\NonGeneralizableTypeTrait; |
21: | use PHPStan\Type\Traits\NonGenericTypeTrait; |
22: | use PHPStan\Type\Traits\NonObjectTypeTrait; |
23: | use PHPStan\Type\Traits\NonRemoveableTypeTrait; |
24: | use PHPStan\Type\Traits\UndecidedBooleanTypeTrait; |
25: | use PHPStan\Type\Traits\UndecidedComparisonCompoundTypeTrait; |
26: | use PHPStan\Type\Type; |
27: | use PHPStan\Type\TypeCombinator; |
28: | use PHPStan\Type\UnionType; |
29: | use PHPStan\Type\VerbosityLevel; |
30: | |
31: | |
32: | class AccessoryArrayListType implements CompoundType, AccessoryType |
33: | { |
34: | |
35: | use MaybeCallableTypeTrait; |
36: | use NonObjectTypeTrait; |
37: | use NonGenericTypeTrait; |
38: | use UndecidedBooleanTypeTrait; |
39: | use UndecidedComparisonCompoundTypeTrait; |
40: | use NonRemoveableTypeTrait; |
41: | use NonGeneralizableTypeTrait; |
42: | |
43: | |
44: | public function __construct() |
45: | { |
46: | } |
47: | |
48: | public function getReferencedClasses(): array |
49: | { |
50: | return []; |
51: | } |
52: | |
53: | public function getObjectClassNames(): array |
54: | { |
55: | return []; |
56: | } |
57: | |
58: | public function getObjectClassReflections(): array |
59: | { |
60: | return []; |
61: | } |
62: | |
63: | public function getArrays(): array |
64: | { |
65: | return []; |
66: | } |
67: | |
68: | public function getConstantArrays(): array |
69: | { |
70: | return []; |
71: | } |
72: | |
73: | public function getConstantStrings(): array |
74: | { |
75: | return []; |
76: | } |
77: | |
78: | public function accepts(Type $type, bool $strictTypes): AcceptsResult |
79: | { |
80: | if ($type instanceof CompoundType) { |
81: | return $type->isAcceptedBy($this, $strictTypes); |
82: | } |
83: | |
84: | $isArray = $type->isArray(); |
85: | $isList = $type->isList(); |
86: | |
87: | return new AcceptsResult($isArray->and($isList), []); |
88: | } |
89: | |
90: | public function isSuperTypeOf(Type $type): IsSuperTypeOfResult |
91: | { |
92: | if ($this->equals($type)) { |
93: | return IsSuperTypeOfResult::createYes(); |
94: | } |
95: | |
96: | if ($type instanceof CompoundType) { |
97: | return $type->isSubTypeOf($this); |
98: | } |
99: | |
100: | return new IsSuperTypeOfResult($type->isArray()->and($type->isList()), []); |
101: | } |
102: | |
103: | public function isSubTypeOf(Type $otherType): IsSuperTypeOfResult |
104: | { |
105: | if ($otherType instanceof UnionType || $otherType instanceof IntersectionType) { |
106: | return $otherType->isSuperTypeOf($this); |
107: | } |
108: | |
109: | return (new IsSuperTypeOfResult($otherType->isArray()->and($otherType->isList()), [])) |
110: | ->and($otherType instanceof self ? IsSuperTypeOfResult::createYes() : IsSuperTypeOfResult::createMaybe()); |
111: | } |
112: | |
113: | public function isAcceptedBy(Type $acceptingType, bool $strictTypes): AcceptsResult |
114: | { |
115: | return $this->isSubTypeOf($acceptingType)->toAcceptsResult(); |
116: | } |
117: | |
118: | public function equals(Type $type): bool |
119: | { |
120: | return $type instanceof self; |
121: | } |
122: | |
123: | public function describe(VerbosityLevel $level): string |
124: | { |
125: | return 'list'; |
126: | } |
127: | |
128: | public function isOffsetAccessible(): TrinaryLogic |
129: | { |
130: | return TrinaryLogic::createYes(); |
131: | } |
132: | |
133: | public function isOffsetAccessLegal(): TrinaryLogic |
134: | { |
135: | return TrinaryLogic::createYes(); |
136: | } |
137: | |
138: | public function hasOffsetValueType(Type $offsetType): TrinaryLogic |
139: | { |
140: | return $this->getIterableKeyType()->isSuperTypeOf($offsetType)->result->and(TrinaryLogic::createMaybe()); |
141: | } |
142: | |
143: | public function getOffsetValueType(Type $offsetType): Type |
144: | { |
145: | return new MixedType(); |
146: | } |
147: | |
148: | public function setOffsetValueType(?Type $offsetType, Type $valueType, bool $unionValues = true): Type |
149: | { |
150: | if ($offsetType === null || (new ConstantIntegerType(0))->isSuperTypeOf($offsetType)->yes()) { |
151: | return $this; |
152: | } |
153: | |
154: | return new ErrorType(); |
155: | } |
156: | |
157: | public function setExistingOffsetValueType(Type $offsetType, Type $valueType): Type |
158: | { |
159: | if ((new ConstantIntegerType(0))->isSuperTypeOf($offsetType)->yes()) { |
160: | return $this; |
161: | } |
162: | |
163: | return new ErrorType(); |
164: | } |
165: | |
166: | public function unsetOffset(Type $offsetType): Type |
167: | { |
168: | if ($this->hasOffsetValueType($offsetType)->no()) { |
169: | return $this; |
170: | } |
171: | |
172: | return new ErrorType(); |
173: | } |
174: | |
175: | public function getKeysArray(): Type |
176: | { |
177: | return $this; |
178: | } |
179: | |
180: | public function getValuesArray(): Type |
181: | { |
182: | return $this; |
183: | } |
184: | |
185: | public function chunkArray(Type $lengthType, TrinaryLogic $preserveKeys): Type |
186: | { |
187: | return $this; |
188: | } |
189: | |
190: | public function fillKeysArray(Type $valueType): Type |
191: | { |
192: | return new MixedType(); |
193: | } |
194: | |
195: | public function flipArray(): Type |
196: | { |
197: | return new MixedType(); |
198: | } |
199: | |
200: | public function intersectKeyArray(Type $otherArraysType): Type |
201: | { |
202: | if ($otherArraysType->isList()->yes()) { |
203: | return $this; |
204: | } |
205: | |
206: | return new MixedType(); |
207: | } |
208: | |
209: | public function popArray(): Type |
210: | { |
211: | return $this; |
212: | } |
213: | |
214: | public function reverseArray(TrinaryLogic $preserveKeys): Type |
215: | { |
216: | if ($preserveKeys->no()) { |
217: | return $this; |
218: | } |
219: | |
220: | return new MixedType(); |
221: | } |
222: | |
223: | public function searchArray(Type $needleType): Type |
224: | { |
225: | return new MixedType(); |
226: | } |
227: | |
228: | public function shiftArray(): Type |
229: | { |
230: | return $this; |
231: | } |
232: | |
233: | public function shuffleArray(): Type |
234: | { |
235: | return $this; |
236: | } |
237: | |
238: | public function sliceArray(Type $offsetType, Type $lengthType, TrinaryLogic $preserveKeys): Type |
239: | { |
240: | if ($preserveKeys->no()) { |
241: | return $this; |
242: | } |
243: | |
244: | if ((new ConstantIntegerType(0))->isSuperTypeOf($offsetType)->yes()) { |
245: | return $this; |
246: | } |
247: | |
248: | return new MixedType(); |
249: | } |
250: | |
251: | public function isIterable(): TrinaryLogic |
252: | { |
253: | return TrinaryLogic::createYes(); |
254: | } |
255: | |
256: | public function isIterableAtLeastOnce(): TrinaryLogic |
257: | { |
258: | return TrinaryLogic::createMaybe(); |
259: | } |
260: | |
261: | public function getArraySize(): Type |
262: | { |
263: | return IntegerRangeType::fromInterval(0, null); |
264: | } |
265: | |
266: | public function getIterableKeyType(): Type |
267: | { |
268: | return IntegerRangeType::fromInterval(0, null); |
269: | } |
270: | |
271: | public function getFirstIterableKeyType(): Type |
272: | { |
273: | return new ConstantIntegerType(0); |
274: | } |
275: | |
276: | public function getLastIterableKeyType(): Type |
277: | { |
278: | return $this->getIterableKeyType(); |
279: | } |
280: | |
281: | public function getIterableValueType(): Type |
282: | { |
283: | return new MixedType(); |
284: | } |
285: | |
286: | public function getFirstIterableValueType(): Type |
287: | { |
288: | return new MixedType(); |
289: | } |
290: | |
291: | public function getLastIterableValueType(): Type |
292: | { |
293: | return new MixedType(); |
294: | } |
295: | |
296: | public function isArray(): TrinaryLogic |
297: | { |
298: | return TrinaryLogic::createYes(); |
299: | } |
300: | |
301: | public function isConstantArray(): TrinaryLogic |
302: | { |
303: | return TrinaryLogic::createMaybe(); |
304: | } |
305: | |
306: | public function isOversizedArray(): TrinaryLogic |
307: | { |
308: | return TrinaryLogic::createMaybe(); |
309: | } |
310: | |
311: | public function isList(): TrinaryLogic |
312: | { |
313: | return TrinaryLogic::createYes(); |
314: | } |
315: | |
316: | public function isNull(): TrinaryLogic |
317: | { |
318: | return TrinaryLogic::createNo(); |
319: | } |
320: | |
321: | public function isConstantValue(): TrinaryLogic |
322: | { |
323: | return TrinaryLogic::createMaybe(); |
324: | } |
325: | |
326: | public function isConstantScalarValue(): TrinaryLogic |
327: | { |
328: | return TrinaryLogic::createNo(); |
329: | } |
330: | |
331: | public function getConstantScalarTypes(): array |
332: | { |
333: | return []; |
334: | } |
335: | |
336: | public function getConstantScalarValues(): array |
337: | { |
338: | return []; |
339: | } |
340: | |
341: | public function isTrue(): TrinaryLogic |
342: | { |
343: | return TrinaryLogic::createNo(); |
344: | } |
345: | |
346: | public function isFalse(): TrinaryLogic |
347: | { |
348: | return TrinaryLogic::createNo(); |
349: | } |
350: | |
351: | public function isBoolean(): TrinaryLogic |
352: | { |
353: | return TrinaryLogic::createNo(); |
354: | } |
355: | |
356: | public function isFloat(): TrinaryLogic |
357: | { |
358: | return TrinaryLogic::createNo(); |
359: | } |
360: | |
361: | public function isInteger(): TrinaryLogic |
362: | { |
363: | return TrinaryLogic::createNo(); |
364: | } |
365: | |
366: | public function isString(): TrinaryLogic |
367: | { |
368: | return TrinaryLogic::createNo(); |
369: | } |
370: | |
371: | public function isNumericString(): TrinaryLogic |
372: | { |
373: | return TrinaryLogic::createNo(); |
374: | } |
375: | |
376: | public function isNonEmptyString(): TrinaryLogic |
377: | { |
378: | return TrinaryLogic::createNo(); |
379: | } |
380: | |
381: | public function isNonFalsyString(): TrinaryLogic |
382: | { |
383: | return TrinaryLogic::createNo(); |
384: | } |
385: | |
386: | public function isLiteralString(): TrinaryLogic |
387: | { |
388: | return TrinaryLogic::createNo(); |
389: | } |
390: | |
391: | public function isLowercaseString(): TrinaryLogic |
392: | { |
393: | return TrinaryLogic::createNo(); |
394: | } |
395: | |
396: | public function isClassString(): TrinaryLogic |
397: | { |
398: | return TrinaryLogic::createNo(); |
399: | } |
400: | |
401: | public function isUppercaseString(): TrinaryLogic |
402: | { |
403: | return TrinaryLogic::createNo(); |
404: | } |
405: | |
406: | public function getClassStringObjectType(): Type |
407: | { |
408: | return new ErrorType(); |
409: | } |
410: | |
411: | public function getObjectTypeOrClassStringObjectType(): Type |
412: | { |
413: | return new ErrorType(); |
414: | } |
415: | |
416: | public function isVoid(): TrinaryLogic |
417: | { |
418: | return TrinaryLogic::createNo(); |
419: | } |
420: | |
421: | public function isScalar(): TrinaryLogic |
422: | { |
423: | return TrinaryLogic::createNo(); |
424: | } |
425: | |
426: | public function looseCompare(Type $type, PhpVersion $phpVersion): BooleanType |
427: | { |
428: | return new BooleanType(); |
429: | } |
430: | |
431: | public function toNumber(): Type |
432: | { |
433: | return new ErrorType(); |
434: | } |
435: | |
436: | public function toAbsoluteNumber(): Type |
437: | { |
438: | return new ErrorType(); |
439: | } |
440: | |
441: | public function toInteger(): Type |
442: | { |
443: | return TypeCombinator::union( |
444: | new ConstantIntegerType(0), |
445: | new ConstantIntegerType(1), |
446: | ); |
447: | } |
448: | |
449: | public function toFloat(): Type |
450: | { |
451: | return TypeCombinator::union( |
452: | new ConstantFloatType(0.0), |
453: | new ConstantFloatType(1.0), |
454: | ); |
455: | } |
456: | |
457: | public function toString(): Type |
458: | { |
459: | return new ErrorType(); |
460: | } |
461: | |
462: | public function toArray(): Type |
463: | { |
464: | return $this; |
465: | } |
466: | |
467: | public function toArrayKey(): Type |
468: | { |
469: | return new ErrorType(); |
470: | } |
471: | |
472: | public function traverse(callable $cb): Type |
473: | { |
474: | return $this; |
475: | } |
476: | |
477: | public function traverseSimultaneously(Type $right, callable $cb): Type |
478: | { |
479: | return $this; |
480: | } |
481: | |
482: | public function exponentiate(Type $exponent): Type |
483: | { |
484: | return new ErrorType(); |
485: | } |
486: | |
487: | public function getFiniteTypes(): array |
488: | { |
489: | return []; |
490: | } |
491: | |
492: | public function toPhpDocNode(): TypeNode |
493: | { |
494: | return new IdentifierTypeNode('list'); |
495: | } |
496: | |
497: | } |
498: | |