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