From f68596823a23349c7afb2686e069188f5d8e4cf5 Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Wed, 26 May 2021 15:52:16 +0200 Subject: [PATCH] More BC promise-covered methods --- src/Analyser/MutatingScope.php | 43 +++++++++++++++++++ src/Analyser/NodeScopeResolver.php | 1 + src/Reflection/FunctionVariant.php | 1 + src/Reflection/FunctionVariantWithPhpDocs.php | 2 + .../ParametersAcceptorWithPhpDocs.php | 1 + src/Reflection/ReflectionWithFilename.php | 1 + .../Constant/ConstantArrayTypeAndMethod.php | 1 + src/Type/ConstantTypeHelper.php | 1 + 8 files changed, 51 insertions(+) diff --git a/src/Analyser/MutatingScope.php b/src/Analyser/MutatingScope.php index ad98ea2616..45117cf3bd 100644 --- a/src/Analyser/MutatingScope.php +++ b/src/Analyser/MutatingScope.php @@ -268,11 +268,13 @@ public function __construct( $this->parentScope = $parentScope; } + /** @api */ public function getFile(): string { return $this->context->getFile(); } + /** @api */ public function getFileDescription(): string { if ($this->context->getTraitReflection() === null) { @@ -299,6 +301,7 @@ public function getFileDescription(): string ); } + /** @api */ public function isDeclareStrictTypes(): bool { return $this->declareStrictTypes; @@ -316,27 +319,32 @@ public function enterDeclareStrictTypes(): self ); } + /** @api */ public function isInClass(): bool { return $this->context->getClassReflection() !== null; } + /** @api */ public function isInTrait(): bool { return $this->context->getTraitReflection() !== null; } + /** @api */ public function getClassReflection(): ?ClassReflection { return $this->context->getClassReflection(); } + /** @api */ public function getTraitReflection(): ?ClassReflection { return $this->context->getTraitReflection(); } /** + * @api * @return \PHPStan\Reflection\FunctionReflection|\PHPStan\Reflection\MethodReflection|null */ public function getFunction() @@ -344,16 +352,19 @@ public function getFunction() return $this->function; } + /** @api */ public function getFunctionName(): ?string { return $this->function !== null ? $this->function->getName() : null; } + /** @api */ public function getNamespace(): ?string { return $this->namespace; } + /** @api */ public function getParentScope(): ?Scope { return $this->parentScope; @@ -367,6 +378,7 @@ private function getVariableTypes(): array return $this->variableTypes; } + /** @api */ public function canAnyVariableExist(): bool { return ($this->function === null && !$this->isInAnonymousFunction()) || $this->afterExtractCall; @@ -449,6 +461,7 @@ public function afterClearstatcacheCall(): self ); } + /** @api */ public function hasVariableType(string $variableName): TrinaryLogic { if ($this->isGlobalVariable($variableName)) { @@ -466,6 +479,7 @@ public function hasVariableType(string $variableName): TrinaryLogic return $this->variableTypes[$variableName]->getCertainty(); } + /** @api */ public function getVariableType(string $variableName): Type { if ($this->isGlobalVariable($variableName)) { @@ -484,6 +498,7 @@ public function getVariableType(string $variableName): Type } /** + * @api * @return array */ public function getDefinedVariables(): array @@ -515,6 +530,7 @@ private function isGlobalVariable(string $variableName): bool ], true); } + /** @api */ public function hasConstant(Name $name): bool { $isCompilerHaltOffset = $name->toString() === '__COMPILER_HALT_OFFSET__'; @@ -560,16 +576,19 @@ private function fileHasCompilerHaltStatementCalls(): bool return false; } + /** @api */ public function isInAnonymousFunction(): bool { return $this->anonymousFunctionReflection !== null; } + /** @api */ public function getAnonymousFunctionReflection(): ?ParametersAcceptor { return $this->anonymousFunctionReflection; } + /** @api */ public function getAnonymousFunctionReturnType(): ?\PHPStan\Type\Type { if ($this->anonymousFunctionReflection === null) { @@ -579,6 +598,7 @@ public function getAnonymousFunctionReturnType(): ?\PHPStan\Type\Type return $this->anonymousFunctionReflection->getReturnType(); } + /** @api */ public function getType(Expr $node): Type { $key = $this->getNodeKey($node); @@ -2155,6 +2175,7 @@ private function resolveConstantType(string $constantName, Type $constantType): return $constantType; } + /** @api */ public function getNativeType(Expr $expr): Type { $key = $this->getNodeKey($expr); @@ -2177,6 +2198,7 @@ public function getNativeType(Expr $expr): Type return $this->getType($expr); } + /** @api */ public function doNotTreatPhpDocTypesAsCertain(): Scope { if (!$this->treatPhpDocTypesAsCertain) { @@ -2409,6 +2431,7 @@ private function resolveExactName(Name $name): ?string return $originalClass; } + /** @api */ public function resolveName(Name $name): string { $originalClass = (string) $name; @@ -2432,6 +2455,7 @@ public function resolveName(Name $name): string return $originalClass; } + /** @api */ public function resolveTypeByName(Name $name): TypeWithClassName { if ($name->toLowerString() === 'static' && $this->isInClass()) { @@ -2459,6 +2483,7 @@ public function resolveTypeByName(Name $name): TypeWithClassName } /** + * @api * @param mixed $value */ public function getTypeFromValue($value): Type @@ -2466,6 +2491,7 @@ public function getTypeFromValue($value): Type return ConstantTypeHelper::getTypeFromValue($value); } + /** @api */ public function isSpecified(Expr $node): bool { $exprString = $this->getNodeKey($node); @@ -2528,6 +2554,7 @@ public function popInFunctionCall(): self ); } + /** @api */ public function isInClassExists(string $className): bool { foreach ($this->inFunctionCallsStack as $inFunctionCall) { @@ -2550,6 +2577,7 @@ public function isInClassExists(string $className): bool return (new ConstantBooleanType(true))->isSuperTypeOf($this->getType($expr))->yes(); } + /** @api */ public function enterClass(ClassReflection $classReflection): self { return $this->scopeFactory->create( @@ -2581,6 +2609,7 @@ public function enterTrait(ClassReflection $traitReflection): self } /** + * @api * @param Node\Stmt\ClassMethod $classMethod * @param TemplateTypeMap $templateTypeMap * @param Type[] $phpDocParameterTypes @@ -2694,6 +2723,7 @@ private function getRealParameterDefaultValues(Node\FunctionLike $functionLike): } /** + * @api * @param Node\Stmt\Function_ $function * @param TemplateTypeMap $templateTypeMap * @param Type[] $phpDocParameterTypes @@ -2859,12 +2889,14 @@ public function enterClosureCall(Type $thisType): self ); } + /** @api */ public function isInClosureBind(): bool { return $this->inClosureBindScopeClass !== null; } /** + * @api * @param \PhpParser\Node\Expr\Closure $closure * @param \PHPStan\Reflection\ParameterReflection[]|null $callableParameters * @return self @@ -2994,6 +3026,7 @@ private function enterAnonymousFunctionWithoutReflection( ); } + /** @api */ public function enterArrowFunction(Expr\ArrowFunction $arrowFunction): self { $anonymousFunctionReflection = $this->getType($arrowFunction); @@ -3133,6 +3166,7 @@ public function isParameterValueNullable(Node\Param $parameter): bool } /** + * @api * @param \PhpParser\Node\Name|\PhpParser\Node\Identifier|\PhpParser\Node\NullableType|\PhpParser\Node\UnionType|null $type * @param bool $isNullable * @param bool $isVariadic @@ -3270,6 +3304,7 @@ public function exitExpressionAssign(Expr $expr): self ); } + /** @api */ public function isInExpressionAssign(Expr $expr): bool { $exprString = $this->getNodeKey($expr); @@ -3602,6 +3637,7 @@ public function removeTypeFromExpression(Expr $expr, Type $typeToRemove): self } /** + * @api * @param \PhpParser\Node\Expr $expr * @return \PHPStan\Analyser\MutatingScope */ @@ -3612,6 +3648,7 @@ public function filterByTruthyValue(Expr $expr): Scope } /** + * @api * @param \PhpParser\Node\Expr $expr * @return \PHPStan\Analyser\MutatingScope */ @@ -3829,6 +3866,7 @@ public function exitFirstLevelStatements(): self ); } + /** @api */ public function isInFirstLevelStatement(): bool { return $this->inFirstLevelStatement; @@ -4558,11 +4596,13 @@ private function compareVariableTypeHolders(array $variableTypeHolders, array $o return true; } + /** @api */ public function canAccessProperty(PropertyReflection $propertyReflection): bool { return $this->canAccessClassMember($propertyReflection); } + /** @api */ public function canCallMethod(MethodReflection $methodReflection): bool { if ($this->canAccessClassMember($methodReflection)) { @@ -4572,6 +4612,7 @@ public function canCallMethod(MethodReflection $methodReflection): bool return $this->canAccessClassMember($methodReflection->getPrototype()); } + /** @api */ public function canAccessConstant(ConstantReflection $constantReflection): bool { return $this->canAccessClassMember($constantReflection); @@ -4782,6 +4823,7 @@ private function getTypeToInstantiateForNew(Type $type): Type return $decidedType; } + /** @api */ public function getMethodReflection(Type $typeWithMethod, string $methodName): ?MethodReflection { if ($typeWithMethod instanceof UnionType) { @@ -4851,6 +4893,7 @@ private function methodCallReturnType(Type $typeWithMethod, string $methodName, )->getReturnType(); } + /** @api */ public function getPropertyReflection(Type $typeWithProperty, string $propertyName): ?PropertyReflection { if ($typeWithProperty instanceof UnionType) { diff --git a/src/Analyser/NodeScopeResolver.php b/src/Analyser/NodeScopeResolver.php index 35281adfe4..454bc03cfb 100644 --- a/src/Analyser/NodeScopeResolver.php +++ b/src/Analyser/NodeScopeResolver.php @@ -223,6 +223,7 @@ public function __construct( } /** + * @api * @param string[] $files */ public function setAnalysedFiles(array $files): void diff --git a/src/Reflection/FunctionVariant.php b/src/Reflection/FunctionVariant.php index 4a56405fff..9a354bbbb2 100644 --- a/src/Reflection/FunctionVariant.php +++ b/src/Reflection/FunctionVariant.php @@ -5,6 +5,7 @@ use PHPStan\Type\Generic\TemplateTypeMap; use PHPStan\Type\Type; +/** @api */ class FunctionVariant implements ParametersAcceptor { diff --git a/src/Reflection/FunctionVariantWithPhpDocs.php b/src/Reflection/FunctionVariantWithPhpDocs.php index 73e0d6f1e1..0a9554f394 100644 --- a/src/Reflection/FunctionVariantWithPhpDocs.php +++ b/src/Reflection/FunctionVariantWithPhpDocs.php @@ -5,6 +5,7 @@ use PHPStan\Type\Generic\TemplateTypeMap; use PHPStan\Type\Type; +/** @api */ class FunctionVariantWithPhpDocs extends FunctionVariant implements ParametersAcceptorWithPhpDocs { @@ -13,6 +14,7 @@ class FunctionVariantWithPhpDocs extends FunctionVariant implements ParametersAc private Type $nativeReturnType; /** + * @api * @param TemplateTypeMap $templateTypeMap * @param array $parameters * @param bool $isVariadic diff --git a/src/Reflection/ParametersAcceptorWithPhpDocs.php b/src/Reflection/ParametersAcceptorWithPhpDocs.php index fbc22be4ea..de4c7e675f 100644 --- a/src/Reflection/ParametersAcceptorWithPhpDocs.php +++ b/src/Reflection/ParametersAcceptorWithPhpDocs.php @@ -4,6 +4,7 @@ use PHPStan\Type\Type; +/** @api */ interface ParametersAcceptorWithPhpDocs extends ParametersAcceptor { diff --git a/src/Reflection/ReflectionWithFilename.php b/src/Reflection/ReflectionWithFilename.php index 6971eb4873..5bedac9600 100644 --- a/src/Reflection/ReflectionWithFilename.php +++ b/src/Reflection/ReflectionWithFilename.php @@ -2,6 +2,7 @@ namespace PHPStan\Reflection; +/** @api */ interface ReflectionWithFilename { diff --git a/src/Type/Constant/ConstantArrayTypeAndMethod.php b/src/Type/Constant/ConstantArrayTypeAndMethod.php index 548254e1e0..3bc1809ea8 100644 --- a/src/Type/Constant/ConstantArrayTypeAndMethod.php +++ b/src/Type/Constant/ConstantArrayTypeAndMethod.php @@ -5,6 +5,7 @@ use PHPStan\TrinaryLogic; use PHPStan\Type\Type; +/** @api */ class ConstantArrayTypeAndMethod { diff --git a/src/Type/ConstantTypeHelper.php b/src/Type/ConstantTypeHelper.php index cea611d68c..f8fdd0699a 100644 --- a/src/Type/ConstantTypeHelper.php +++ b/src/Type/ConstantTypeHelper.php @@ -8,6 +8,7 @@ use PHPStan\Type\Constant\ConstantIntegerType; use PHPStan\Type\Constant\ConstantStringType; +/** @api */ class ConstantTypeHelper {