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\MethodReflection;
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\Generic\TemplateTypeMap;
14: use PHPStan\Type\Generic\TemplateTypeReference;
15: use PHPStan\Type\Generic\TemplateTypeVariance;
16:
17: /** @api */
18: interface Type
19: {
20:
21: /**
22: * @return string[]
23: */
24: public function getReferencedClasses(): array;
25:
26: public function accepts(Type $type, bool $strictTypes): TrinaryLogic;
27:
28: public function isSuperTypeOf(Type $type): TrinaryLogic;
29:
30: public function equals(Type $type): bool;
31:
32: public function describe(VerbosityLevel $level): string;
33:
34: public function canAccessProperties(): TrinaryLogic;
35:
36: public function hasProperty(string $propertyName): TrinaryLogic;
37:
38: public function getProperty(string $propertyName, ClassMemberAccessAnswerer $scope): PropertyReflection;
39:
40: public function getUnresolvedPropertyPrototype(string $propertyName, ClassMemberAccessAnswerer $scope): UnresolvedPropertyPrototypeReflection;
41:
42: public function canCallMethods(): TrinaryLogic;
43:
44: public function hasMethod(string $methodName): TrinaryLogic;
45:
46: public function getMethod(string $methodName, ClassMemberAccessAnswerer $scope): MethodReflection;
47:
48: public function getUnresolvedMethodPrototype(string $methodName, ClassMemberAccessAnswerer $scope): UnresolvedMethodPrototypeReflection;
49:
50: public function canAccessConstants(): TrinaryLogic;
51:
52: public function hasConstant(string $constantName): TrinaryLogic;
53:
54: public function getConstant(string $constantName): ConstantReflection;
55:
56: public function isIterable(): TrinaryLogic;
57:
58: public function isIterableAtLeastOnce(): TrinaryLogic;
59:
60: public function getIterableKeyType(): Type;
61:
62: public function getIterableValueType(): Type;
63:
64: public function isArray(): TrinaryLogic;
65:
66: public function isOversizedArray(): TrinaryLogic;
67:
68: public function isOffsetAccessible(): TrinaryLogic;
69:
70: public function hasOffsetValueType(Type $offsetType): TrinaryLogic;
71:
72: public function getOffsetValueType(Type $offsetType): Type;
73:
74: public function setOffsetValueType(?Type $offsetType, Type $valueType, bool $unionValues = true): Type;
75:
76: public function unsetOffset(Type $offsetType): Type;
77:
78: public function isCallable(): TrinaryLogic;
79:
80: /**
81: * @return ParametersAcceptor[]
82: */
83: public function getCallableParametersAcceptors(ClassMemberAccessAnswerer $scope): array;
84:
85: public function isCloneable(): TrinaryLogic;
86:
87: public function toBoolean(): BooleanType;
88:
89: public function toNumber(): Type;
90:
91: public function toInteger(): Type;
92:
93: public function toFloat(): Type;
94:
95: public function toString(): Type;
96:
97: public function toArray(): Type;
98:
99: public function isSmallerThan(Type $otherType): TrinaryLogic;
100:
101: public function isSmallerThanOrEqual(Type $otherType): TrinaryLogic;
102:
103: public function isString(): TrinaryLogic;
104:
105: public function isNumericString(): TrinaryLogic;
106:
107: public function isNonEmptyString(): TrinaryLogic;
108:
109: public function isNonFalsyString(): TrinaryLogic;
110:
111: public function isLiteralString(): TrinaryLogic;
112:
113: public function getSmallerType(): Type;
114:
115: public function getSmallerOrEqualType(): Type;
116:
117: public function getGreaterType(): Type;
118:
119: public function getGreaterOrEqualType(): Type;
120:
121: /**
122: * Infers template types
123: *
124: * Infers the real Type of the TemplateTypes found in $this, based on
125: * the received Type.
126: */
127: public function inferTemplateTypes(Type $receivedType): TemplateTypeMap;
128:
129: /**
130: * Returns the template types referenced by this Type, recursively
131: *
132: * The return value is a list of TemplateTypeReferences, who contain the
133: * referenced template type as well as the variance position in which it was
134: * found.
135: *
136: * For example, calling this on array<Foo<T>,Bar> (with T a template type)
137: * will return one TemplateTypeReference for the type T.
138: *
139: * @param TemplateTypeVariance $positionVariance The variance position in
140: * which the receiver type was
141: * found.
142: *
143: * @return TemplateTypeReference[]
144: */
145: public function getReferencedTemplateTypes(TemplateTypeVariance $positionVariance): array;
146:
147: /**
148: * Traverses inner types
149: *
150: * Returns a new instance with all inner types mapped through $cb. Might
151: * return the same instance if inner types did not change.
152: *
153: * @param callable(Type):Type $cb
154: */
155: public function traverse(callable $cb): Type;
156:
157: /**
158: * Return the difference with another type, or null if it cannot be represented.
159: *
160: * @see TypeCombinator::remove()
161: */
162: public function tryRemove(Type $typeToRemove): ?Type;
163:
164: public function generalize(GeneralizePrecision $precision): Type;
165:
166: /**
167: * @param mixed[] $properties
168: */
169: public static function __set_state(array $properties): self;
170:
171: }
172: