1: <?php declare(strict_types = 1);
2:
3: namespace PHPStan\Type\Accessory;
4:
5: use PHPStan\TrinaryLogic;
6: use PHPStan\Type\CompoundType;
7: use PHPStan\Type\Constant\ConstantFloatType;
8: use PHPStan\Type\Constant\ConstantIntegerType;
9: use PHPStan\Type\ErrorType;
10: use PHPStan\Type\IntegerRangeType;
11: use PHPStan\Type\IntersectionType;
12: use PHPStan\Type\MixedType;
13: use PHPStan\Type\Traits\MaybeCallableTypeTrait;
14: use PHPStan\Type\Traits\NonGeneralizableTypeTrait;
15: use PHPStan\Type\Traits\NonGenericTypeTrait;
16: use PHPStan\Type\Traits\NonObjectTypeTrait;
17: use PHPStan\Type\Traits\NonRemoveableTypeTrait;
18: use PHPStan\Type\Traits\TruthyBooleanTypeTrait;
19: use PHPStan\Type\Traits\UndecidedComparisonCompoundTypeTrait;
20: use PHPStan\Type\Type;
21: use PHPStan\Type\UnionType;
22: use PHPStan\Type\VerbosityLevel;
23:
24: class NonEmptyArrayType implements CompoundType, AccessoryType
25: {
26:
27: use MaybeCallableTypeTrait;
28: use NonObjectTypeTrait;
29: use TruthyBooleanTypeTrait;
30: use NonGenericTypeTrait;
31: use UndecidedComparisonCompoundTypeTrait;
32: use NonRemoveableTypeTrait;
33: use NonGeneralizableTypeTrait;
34:
35: /** @api */
36: public function __construct()
37: {
38: }
39:
40: public function getReferencedClasses(): array
41: {
42: return [];
43: }
44:
45: public function getArrays(): array
46: {
47: return [];
48: }
49:
50: public function getConstantArrays(): array
51: {
52: return [];
53: }
54:
55: public function getConstantStrings(): array
56: {
57: return [];
58: }
59:
60: public function accepts(Type $type, bool $strictTypes): TrinaryLogic
61: {
62: if ($type instanceof CompoundType) {
63: return $type->isAcceptedBy($this, $strictTypes);
64: }
65:
66: return $type->isArray()
67: ->and($type->isIterableAtLeastOnce());
68: }
69:
70: public function isSuperTypeOf(Type $type): TrinaryLogic
71: {
72: if ($this->equals($type)) {
73: return TrinaryLogic::createYes();
74: }
75:
76: if ($type instanceof CompoundType) {
77: return $type->isSubTypeOf($this);
78: }
79:
80: return $type->isArray()
81: ->and($type->isIterableAtLeastOnce());
82: }
83:
84: public function isSubTypeOf(Type $otherType): TrinaryLogic
85: {
86: if ($otherType instanceof UnionType || $otherType instanceof IntersectionType) {
87: return $otherType->isSuperTypeOf($this);
88: }
89:
90: return $otherType->isArray()
91: ->and($otherType->isIterableAtLeastOnce())
92: ->and($otherType instanceof self ? TrinaryLogic::createYes() : TrinaryLogic::createMaybe());
93: }
94:
95: public function isAcceptedBy(Type $acceptingType, bool $strictTypes): TrinaryLogic
96: {
97: return $this->isSubTypeOf($acceptingType);
98: }
99:
100: public function equals(Type $type): bool
101: {
102: return $type instanceof self;
103: }
104:
105: public function describe(VerbosityLevel $level): string
106: {
107: return 'non-empty-array';
108: }
109:
110: public function isOffsetAccessible(): TrinaryLogic
111: {
112: return TrinaryLogic::createYes();
113: }
114:
115: public function hasOffsetValueType(Type $offsetType): TrinaryLogic
116: {
117: return TrinaryLogic::createMaybe();
118: }
119:
120: public function getOffsetValueType(Type $offsetType): Type
121: {
122: return new MixedType();
123: }
124:
125: public function setOffsetValueType(?Type $offsetType, Type $valueType, bool $unionValues = true): Type
126: {
127: return $this;
128: }
129:
130: public function unsetOffset(Type $offsetType): Type
131: {
132: return new ErrorType();
133: }
134:
135: public function getKeysArray(): Type
136: {
137: return $this;
138: }
139:
140: public function getValuesArray(): Type
141: {
142: return $this;
143: }
144:
145: public function fillKeysArray(Type $valueType): Type
146: {
147: return $this;
148: }
149:
150: public function flipArray(): Type
151: {
152: return $this;
153: }
154:
155: public function intersectKeyArray(Type $otherArraysType): Type
156: {
157: return new MixedType();
158: }
159:
160: public function popArray(): Type
161: {
162: return new MixedType();
163: }
164:
165: public function searchArray(Type $needleType): Type
166: {
167: return new MixedType();
168: }
169:
170: public function shiftArray(): Type
171: {
172: return new MixedType();
173: }
174:
175: public function shuffleArray(): Type
176: {
177: return $this;
178: }
179:
180: public function isIterable(): TrinaryLogic
181: {
182: return TrinaryLogic::createYes();
183: }
184:
185: public function isIterableAtLeastOnce(): TrinaryLogic
186: {
187: return TrinaryLogic::createYes();
188: }
189:
190: public function getArraySize(): Type
191: {
192: return IntegerRangeType::fromInterval(1, null);
193: }
194:
195: public function getIterableKeyType(): Type
196: {
197: return new MixedType();
198: }
199:
200: public function getFirstIterableKeyType(): Type
201: {
202: return new MixedType();
203: }
204:
205: public function getLastIterableKeyType(): Type
206: {
207: return new MixedType();
208: }
209:
210: public function getIterableValueType(): Type
211: {
212: return new MixedType();
213: }
214:
215: public function getFirstIterableValueType(): Type
216: {
217: return new MixedType();
218: }
219:
220: public function getLastIterableValueType(): Type
221: {
222: return new MixedType();
223: }
224:
225: public function isArray(): TrinaryLogic
226: {
227: return TrinaryLogic::createYes();
228: }
229:
230: public function isConstantArray(): TrinaryLogic
231: {
232: return TrinaryLogic::createMaybe();
233: }
234:
235: public function isOversizedArray(): TrinaryLogic
236: {
237: return TrinaryLogic::createMaybe();
238: }
239:
240: public function isList(): TrinaryLogic
241: {
242: return TrinaryLogic::createMaybe();
243: }
244:
245: public function isNull(): TrinaryLogic
246: {
247: return TrinaryLogic::createNo();
248: }
249:
250: public function isTrue(): TrinaryLogic
251: {
252: return TrinaryLogic::createNo();
253: }
254:
255: public function isFalse(): TrinaryLogic
256: {
257: return TrinaryLogic::createNo();
258: }
259:
260: public function isBoolean(): TrinaryLogic
261: {
262: return TrinaryLogic::createNo();
263: }
264:
265: public function isFloat(): TrinaryLogic
266: {
267: return TrinaryLogic::createNo();
268: }
269:
270: public function isInteger(): TrinaryLogic
271: {
272: return TrinaryLogic::createNo();
273: }
274:
275: public function isString(): TrinaryLogic
276: {
277: return TrinaryLogic::createNo();
278: }
279:
280: public function isNumericString(): TrinaryLogic
281: {
282: return TrinaryLogic::createNo();
283: }
284:
285: public function isNonEmptyString(): TrinaryLogic
286: {
287: return TrinaryLogic::createNo();
288: }
289:
290: public function isNonFalsyString(): TrinaryLogic
291: {
292: return TrinaryLogic::createNo();
293: }
294:
295: public function isLiteralString(): TrinaryLogic
296: {
297: return TrinaryLogic::createNo();
298: }
299:
300: public function isClassStringType(): TrinaryLogic
301: {
302: return TrinaryLogic::createNo();
303: }
304:
305: public function isVoid(): TrinaryLogic
306: {
307: return TrinaryLogic::createNo();
308: }
309:
310: public function isScalar(): TrinaryLogic
311: {
312: return TrinaryLogic::createNo();
313: }
314:
315: public function toNumber(): Type
316: {
317: return new ErrorType();
318: }
319:
320: public function toInteger(): Type
321: {
322: return new ConstantIntegerType(1);
323: }
324:
325: public function toFloat(): Type
326: {
327: return new ConstantFloatType(1.0);
328: }
329:
330: public function toString(): Type
331: {
332: return new ErrorType();
333: }
334:
335: public function toArray(): Type
336: {
337: return new MixedType();
338: }
339:
340: public function toArrayKey(): Type
341: {
342: return new ErrorType();
343: }
344:
345: public function traverse(callable $cb): Type
346: {
347: return $this;
348: }
349:
350: public static function __set_state(array $properties): Type
351: {
352: return new self();
353: }
354:
355: }
356: