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