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