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: if ($type instanceof CompoundType) {
80: return $type->isAcceptedBy($this, $strictTypes);
81: }
82:
83: $isArray = $type->isArray();
84: $isList = $type->isList();
85:
86: return new AcceptsResult($isArray->and($isList), []);
87: }
88:
89: public function isSuperTypeOf(Type $type): IsSuperTypeOfResult
90: {
91: if ($this->equals($type)) {
92: return IsSuperTypeOfResult::createYes();
93: }
94:
95: if ($type instanceof CompoundType) {
96: return $type->isSubTypeOf($this);
97: }
98:
99: return new IsSuperTypeOfResult($type->isArray()->and($type->isList()), []);
100: }
101:
102: public function isSubTypeOf(Type $otherType): IsSuperTypeOfResult
103: {
104: if ($otherType instanceof UnionType || $otherType instanceof IntersectionType) {
105: return $otherType->isSuperTypeOf($this);
106: }
107:
108: return (new IsSuperTypeOfResult($otherType->isArray()->and($otherType->isList()), []))
109: ->and($otherType instanceof self ? IsSuperTypeOfResult::createYes() : IsSuperTypeOfResult::createMaybe());
110: }
111:
112: public function isAcceptedBy(Type $acceptingType, bool $strictTypes): AcceptsResult
113: {
114: return $this->isSubTypeOf($acceptingType)->toAcceptsResult();
115: }
116:
117: public function equals(Type $type): bool
118: {
119: return $type instanceof self;
120: }
121:
122: public function describe(VerbosityLevel $level): string
123: {
124: return 'list';
125: }
126:
127: public function isOffsetAccessible(): TrinaryLogic
128: {
129: return TrinaryLogic::createYes();
130: }
131:
132: public function isOffsetAccessLegal(): TrinaryLogic
133: {
134: return TrinaryLogic::createYes();
135: }
136:
137: public function hasOffsetValueType(Type $offsetType): TrinaryLogic
138: {
139: return $this->getIterableKeyType()->isSuperTypeOf($offsetType)->result->and(TrinaryLogic::createMaybe());
140: }
141:
142: public function getOffsetValueType(Type $offsetType): Type
143: {
144: return new MixedType();
145: }
146:
147: public function setOffsetValueType(?Type $offsetType, Type $valueType, bool $unionValues = true): Type
148: {
149: if ($offsetType === null || (new ConstantIntegerType(0))->isSuperTypeOf($offsetType)->yes()) {
150: return $this;
151: }
152:
153: return new ErrorType();
154: }
155:
156: public function setExistingOffsetValueType(Type $offsetType, Type $valueType): Type
157: {
158: return $this;
159: }
160:
161: public function unsetOffset(Type $offsetType): Type
162: {
163: if ($this->hasOffsetValueType($offsetType)->no()) {
164: return $this;
165: }
166:
167: return new ErrorType();
168: }
169:
170: public function getKeysArrayFiltered(Type $filterValueType, TrinaryLogic $strict): Type
171: {
172: return $this->getKeysArray();
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, ?TrinaryLogic $strict = null): 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 spliceArray(Type $offsetType, Type $lengthType, Type $replacementType): Type
252: {
253: return $this;
254: }
255:
256: public function isIterable(): TrinaryLogic
257: {
258: return TrinaryLogic::createYes();
259: }
260:
261: public function isIterableAtLeastOnce(): TrinaryLogic
262: {
263: return TrinaryLogic::createMaybe();
264: }
265:
266: public function getArraySize(): Type
267: {
268: return IntegerRangeType::fromInterval(0, null);
269: }
270:
271: public function getIterableKeyType(): Type
272: {
273: return IntegerRangeType::fromInterval(0, null);
274: }
275:
276: public function getFirstIterableKeyType(): Type
277: {
278: return new ConstantIntegerType(0);
279: }
280:
281: public function getLastIterableKeyType(): Type
282: {
283: return $this->getIterableKeyType();
284: }
285:
286: public function getIterableValueType(): Type
287: {
288: return new MixedType();
289: }
290:
291: public function getFirstIterableValueType(): Type
292: {
293: return new MixedType();
294: }
295:
296: public function getLastIterableValueType(): Type
297: {
298: return new MixedType();
299: }
300:
301: public function isArray(): TrinaryLogic
302: {
303: return TrinaryLogic::createYes();
304: }
305:
306: public function isConstantArray(): TrinaryLogic
307: {
308: return TrinaryLogic::createMaybe();
309: }
310:
311: public function isOversizedArray(): TrinaryLogic
312: {
313: return TrinaryLogic::createMaybe();
314: }
315:
316: public function isList(): TrinaryLogic
317: {
318: return TrinaryLogic::createYes();
319: }
320:
321: public function isNull(): TrinaryLogic
322: {
323: return TrinaryLogic::createNo();
324: }
325:
326: public function isConstantValue(): TrinaryLogic
327: {
328: return TrinaryLogic::createMaybe();
329: }
330:
331: public function isConstantScalarValue(): TrinaryLogic
332: {
333: return TrinaryLogic::createNo();
334: }
335:
336: public function getConstantScalarTypes(): array
337: {
338: return [];
339: }
340:
341: public function getConstantScalarValues(): array
342: {
343: return [];
344: }
345:
346: public function isTrue(): TrinaryLogic
347: {
348: return TrinaryLogic::createNo();
349: }
350:
351: public function isFalse(): TrinaryLogic
352: {
353: return TrinaryLogic::createNo();
354: }
355:
356: public function isBoolean(): TrinaryLogic
357: {
358: return TrinaryLogic::createNo();
359: }
360:
361: public function isFloat(): TrinaryLogic
362: {
363: return TrinaryLogic::createNo();
364: }
365:
366: public function isInteger(): TrinaryLogic
367: {
368: return TrinaryLogic::createNo();
369: }
370:
371: public function isString(): TrinaryLogic
372: {
373: return TrinaryLogic::createNo();
374: }
375:
376: public function isNumericString(): TrinaryLogic
377: {
378: return TrinaryLogic::createNo();
379: }
380:
381: public function isNonEmptyString(): TrinaryLogic
382: {
383: return TrinaryLogic::createNo();
384: }
385:
386: public function isNonFalsyString(): TrinaryLogic
387: {
388: return TrinaryLogic::createNo();
389: }
390:
391: public function isLiteralString(): TrinaryLogic
392: {
393: return TrinaryLogic::createNo();
394: }
395:
396: public function isLowercaseString(): TrinaryLogic
397: {
398: return TrinaryLogic::createNo();
399: }
400:
401: public function isClassString(): TrinaryLogic
402: {
403: return TrinaryLogic::createNo();
404: }
405:
406: public function isUppercaseString(): TrinaryLogic
407: {
408: return TrinaryLogic::createNo();
409: }
410:
411: public function getClassStringObjectType(): Type
412: {
413: return new ErrorType();
414: }
415:
416: public function getObjectTypeOrClassStringObjectType(): Type
417: {
418: return new ErrorType();
419: }
420:
421: public function isVoid(): TrinaryLogic
422: {
423: return TrinaryLogic::createNo();
424: }
425:
426: public function isScalar(): TrinaryLogic
427: {
428: return TrinaryLogic::createNo();
429: }
430:
431: public function looseCompare(Type $type, PhpVersion $phpVersion): BooleanType
432: {
433: return new BooleanType();
434: }
435:
436: public function toNumber(): Type
437: {
438: return new ErrorType();
439: }
440:
441: public function toAbsoluteNumber(): Type
442: {
443: return new ErrorType();
444: }
445:
446: public function toInteger(): Type
447: {
448: return new UnionType([
449: new ConstantIntegerType(0),
450: new ConstantIntegerType(1),
451: ]);
452: }
453:
454: public function toFloat(): Type
455: {
456: return new UnionType([
457: new ConstantFloatType(0.0),
458: new ConstantFloatType(1.0),
459: ]);
460: }
461:
462: public function toString(): Type
463: {
464: return new ErrorType();
465: }
466:
467: public function toArray(): Type
468: {
469: return $this;
470: }
471:
472: public function toArrayKey(): Type
473: {
474: return new ErrorType();
475: }
476:
477: public function toCoercedArgumentType(bool $strictTypes): Type
478: {
479: return $this;
480: }
481:
482: public function traverse(callable $cb): Type
483: {
484: return $this;
485: }
486:
487: public function traverseSimultaneously(Type $right, callable $cb): Type
488: {
489: return $this;
490: }
491:
492: public function exponentiate(Type $exponent): Type
493: {
494: return new ErrorType();
495: }
496:
497: public function getFiniteTypes(): array
498: {
499: return [];
500: }
501:
502: public function toPhpDocNode(): TypeNode
503: {
504: return new IdentifierTypeNode('list');
505: }
506:
507: }
508: