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