1: <?php declare(strict_types = 1);
2:
3: namespace PHPStan\Type;
4:
5: use PHPStan\Reflection\ClassMemberAccessAnswerer;
6: use PHPStan\Reflection\ConstantReflection;
7: use PHPStan\Reflection\ExtendedMethodReflection;
8: use PHPStan\Reflection\ParametersAcceptor;
9: use PHPStan\Reflection\PropertyReflection;
10: use PHPStan\Reflection\Type\UnresolvedMethodPrototypeReflection;
11: use PHPStan\Reflection\Type\UnresolvedPropertyPrototypeReflection;
12: use PHPStan\TrinaryLogic;
13: use PHPStan\Type\Constant\ConstantArrayType;
14: use PHPStan\Type\Constant\ConstantStringType;
15: use PHPStan\Type\Generic\TemplateTypeMap;
16: use PHPStan\Type\Generic\TemplateTypeReference;
17: use PHPStan\Type\Generic\TemplateTypeVariance;
18:
19: /** @api */
20: interface Type
21: {
22:
23: /**
24: * @return string[]
25: */
26: public function getReferencedClasses(): array;
27:
28: /** @return list<ArrayType> */
29: public function getArrays(): array;
30:
31: /** @return list<ConstantArrayType> */
32: public function getConstantArrays(): array;
33:
34: /** @return list<ConstantStringType> */
35: public function getConstantStrings(): array;
36:
37: public function accepts(Type $type, bool $strictTypes): TrinaryLogic;
38:
39: public function isSuperTypeOf(Type $type): TrinaryLogic;
40:
41: public function equals(Type $type): bool;
42:
43: public function describe(VerbosityLevel $level): string;
44:
45: public function canAccessProperties(): TrinaryLogic;
46:
47: public function hasProperty(string $propertyName): TrinaryLogic;
48:
49: public function getProperty(string $propertyName, ClassMemberAccessAnswerer $scope): PropertyReflection;
50:
51: public function getUnresolvedPropertyPrototype(string $propertyName, ClassMemberAccessAnswerer $scope): UnresolvedPropertyPrototypeReflection;
52:
53: public function canCallMethods(): TrinaryLogic;
54:
55: public function hasMethod(string $methodName): TrinaryLogic;
56:
57: public function getMethod(string $methodName, ClassMemberAccessAnswerer $scope): ExtendedMethodReflection;
58:
59: public function getUnresolvedMethodPrototype(string $methodName, ClassMemberAccessAnswerer $scope): UnresolvedMethodPrototypeReflection;
60:
61: public function canAccessConstants(): TrinaryLogic;
62:
63: public function hasConstant(string $constantName): TrinaryLogic;
64:
65: public function getConstant(string $constantName): ConstantReflection;
66:
67: public function isIterable(): TrinaryLogic;
68:
69: public function isIterableAtLeastOnce(): TrinaryLogic;
70:
71: public function getArraySize(): Type;
72:
73: public function getIterableKeyType(): Type;
74:
75: public function getFirstIterableKeyType(): Type;
76:
77: public function getLastIterableKeyType(): Type;
78:
79: public function getIterableValueType(): Type;
80:
81: public function getFirstIterableValueType(): Type;
82:
83: public function getLastIterableValueType(): Type;
84:
85: public function isArray(): TrinaryLogic;
86:
87: public function isConstantArray(): TrinaryLogic;
88:
89: public function isOversizedArray(): TrinaryLogic;
90:
91: public function isList(): TrinaryLogic;
92:
93: public function isOffsetAccessible(): TrinaryLogic;
94:
95: public function hasOffsetValueType(Type $offsetType): TrinaryLogic;
96:
97: public function getOffsetValueType(Type $offsetType): Type;
98:
99: public function setOffsetValueType(?Type $offsetType, Type $valueType, bool $unionValues = true): Type;
100:
101: public function unsetOffset(Type $offsetType): Type;
102:
103: public function getKeysArray(): Type;
104:
105: public function getValuesArray(): Type;
106:
107: public function fillKeysArray(Type $valueType): Type;
108:
109: public function flipArray(): Type;
110:
111: public function intersectKeyArray(Type $otherArraysType): Type;
112:
113: public function popArray(): Type;
114:
115: public function searchArray(Type $needleType): Type;
116:
117: public function shiftArray(): Type;
118:
119: public function shuffleArray(): Type;
120:
121: public function isCallable(): TrinaryLogic;
122:
123: /**
124: * @return ParametersAcceptor[]
125: */
126: public function getCallableParametersAcceptors(ClassMemberAccessAnswerer $scope): array;
127:
128: public function isCloneable(): TrinaryLogic;
129:
130: public function toBoolean(): BooleanType;
131:
132: public function toNumber(): Type;
133:
134: public function toInteger(): Type;
135:
136: public function toFloat(): Type;
137:
138: public function toString(): Type;
139:
140: public function toArray(): Type;
141:
142: public function toArrayKey(): Type;
143:
144: public function isSmallerThan(Type $otherType): TrinaryLogic;
145:
146: public function isSmallerThanOrEqual(Type $otherType): TrinaryLogic;
147:
148: public function isNull(): TrinaryLogic;
149:
150: public function isTrue(): TrinaryLogic;
151:
152: public function isFalse(): TrinaryLogic;
153:
154: public function isBoolean(): TrinaryLogic;
155:
156: public function isFloat(): TrinaryLogic;
157:
158: public function isInteger(): TrinaryLogic;
159:
160: public function isString(): TrinaryLogic;
161:
162: public function isNumericString(): TrinaryLogic;
163:
164: public function isNonEmptyString(): TrinaryLogic;
165:
166: public function isNonFalsyString(): TrinaryLogic;
167:
168: public function isLiteralString(): TrinaryLogic;
169:
170: public function isClassStringType(): TrinaryLogic;
171:
172: public function isVoid(): TrinaryLogic;
173:
174: public function isScalar(): TrinaryLogic;
175:
176: public function getSmallerType(): Type;
177:
178: public function getSmallerOrEqualType(): Type;
179:
180: public function getGreaterType(): Type;
181:
182: public function getGreaterOrEqualType(): Type;
183:
184: /**
185: * Infers template types
186: *
187: * Infers the real Type of the TemplateTypes found in $this, based on
188: * the received Type.
189: */
190: public function inferTemplateTypes(Type $receivedType): TemplateTypeMap;
191:
192: /**
193: * Returns the template types referenced by this Type, recursively
194: *
195: * The return value is a list of TemplateTypeReferences, who contain the
196: * referenced template type as well as the variance position in which it was
197: * found.
198: *
199: * For example, calling this on array<Foo<T>,Bar> (with T a template type)
200: * will return one TemplateTypeReference for the type T.
201: *
202: * @param TemplateTypeVariance $positionVariance The variance position in
203: * which the receiver type was
204: * found.
205: *
206: * @return TemplateTypeReference[]
207: */
208: public function getReferencedTemplateTypes(TemplateTypeVariance $positionVariance): array;
209:
210: /**
211: * Traverses inner types
212: *
213: * Returns a new instance with all inner types mapped through $cb. Might
214: * return the same instance if inner types did not change.
215: *
216: * @param callable(Type):Type $cb
217: */
218: public function traverse(callable $cb): Type;
219:
220: /**
221: * Return the difference with another type, or null if it cannot be represented.
222: *
223: * @see TypeCombinator::remove()
224: */
225: public function tryRemove(Type $typeToRemove): ?Type;
226:
227: public function generalize(GeneralizePrecision $precision): Type;
228:
229: /**
230: * @param mixed[] $properties
231: */
232: public static function __set_state(array $properties): self;
233:
234: }
235: