Skip to content

Commit

Permalink
More BC promise-covered methods
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed May 26, 2021
1 parent 8468a34 commit f685968
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/Analyser/MutatingScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -299,6 +301,7 @@ public function getFileDescription(): string
);
}

/** @api */
public function isDeclareStrictTypes(): bool
{
return $this->declareStrictTypes;
Expand All @@ -316,44 +319,52 @@ 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()
{
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;
Expand All @@ -367,6 +378,7 @@ private function getVariableTypes(): array
return $this->variableTypes;
}

/** @api */
public function canAnyVariableExist(): bool
{
return ($this->function === null && !$this->isInAnonymousFunction()) || $this->afterExtractCall;
Expand Down Expand Up @@ -449,6 +461,7 @@ public function afterClearstatcacheCall(): self
);
}

/** @api */
public function hasVariableType(string $variableName): TrinaryLogic
{
if ($this->isGlobalVariable($variableName)) {
Expand All @@ -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)) {
Expand All @@ -484,6 +498,7 @@ public function getVariableType(string $variableName): Type
}

/**
* @api
* @return array<int, string>
*/
public function getDefinedVariables(): array
Expand Down Expand Up @@ -515,6 +530,7 @@ private function isGlobalVariable(string $variableName): bool
], true);
}

/** @api */
public function hasConstant(Name $name): bool
{
$isCompilerHaltOffset = $name->toString() === '__COMPILER_HALT_OFFSET__';
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
Expand Down Expand Up @@ -2155,6 +2175,7 @@ private function resolveConstantType(string $constantName, Type $constantType):
return $constantType;
}

/** @api */
public function getNativeType(Expr $expr): Type
{
$key = $this->getNodeKey($expr);
Expand All @@ -2177,6 +2198,7 @@ public function getNativeType(Expr $expr): Type
return $this->getType($expr);
}

/** @api */
public function doNotTreatPhpDocTypesAsCertain(): Scope
{
if (!$this->treatPhpDocTypesAsCertain) {
Expand Down Expand Up @@ -2409,6 +2431,7 @@ private function resolveExactName(Name $name): ?string
return $originalClass;
}

/** @api */
public function resolveName(Name $name): string
{
$originalClass = (string) $name;
Expand All @@ -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()) {
Expand Down Expand Up @@ -2459,13 +2483,15 @@ public function resolveTypeByName(Name $name): TypeWithClassName
}

/**
* @api
* @param mixed $value
*/
public function getTypeFromValue($value): Type
{
return ConstantTypeHelper::getTypeFromValue($value);
}

/** @api */
public function isSpecified(Expr $node): bool
{
$exprString = $this->getNodeKey($node);
Expand Down Expand Up @@ -2528,6 +2554,7 @@ public function popInFunctionCall(): self
);
}

/** @api */
public function isInClassExists(string $className): bool
{
foreach ($this->inFunctionCallsStack as $inFunctionCall) {
Expand All @@ -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(
Expand Down Expand Up @@ -2581,6 +2609,7 @@ public function enterTrait(ClassReflection $traitReflection): self
}

/**
* @api
* @param Node\Stmt\ClassMethod $classMethod
* @param TemplateTypeMap $templateTypeMap
* @param Type[] $phpDocParameterTypes
Expand Down Expand Up @@ -2694,6 +2723,7 @@ private function getRealParameterDefaultValues(Node\FunctionLike $functionLike):
}

/**
* @api
* @param Node\Stmt\Function_ $function
* @param TemplateTypeMap $templateTypeMap
* @param Type[] $phpDocParameterTypes
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -2994,6 +3026,7 @@ private function enterAnonymousFunctionWithoutReflection(
);
}

/** @api */
public function enterArrowFunction(Expr\ArrowFunction $arrowFunction): self
{
$anonymousFunctionReflection = $this->getType($arrowFunction);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -3270,6 +3304,7 @@ public function exitExpressionAssign(Expr $expr): self
);
}

/** @api */
public function isInExpressionAssign(Expr $expr): bool
{
$exprString = $this->getNodeKey($expr);
Expand Down Expand Up @@ -3602,6 +3637,7 @@ public function removeTypeFromExpression(Expr $expr, Type $typeToRemove): self
}

/**
* @api
* @param \PhpParser\Node\Expr $expr
* @return \PHPStan\Analyser\MutatingScope
*/
Expand All @@ -3612,6 +3648,7 @@ public function filterByTruthyValue(Expr $expr): Scope
}

/**
* @api
* @param \PhpParser\Node\Expr $expr
* @return \PHPStan\Analyser\MutatingScope
*/
Expand Down Expand Up @@ -3829,6 +3866,7 @@ public function exitFirstLevelStatements(): self
);
}

/** @api */
public function isInFirstLevelStatement(): bool
{
return $this->inFirstLevelStatement;
Expand Down Expand Up @@ -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)) {
Expand All @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions src/Analyser/NodeScopeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ public function __construct(
}

/**
* @api
* @param string[] $files
*/
public function setAnalysedFiles(array $files): void
Expand Down
1 change: 1 addition & 0 deletions src/Reflection/FunctionVariant.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use PHPStan\Type\Generic\TemplateTypeMap;
use PHPStan\Type\Type;

/** @api */
class FunctionVariant implements ParametersAcceptor
{

Expand Down
2 changes: 2 additions & 0 deletions src/Reflection/FunctionVariantWithPhpDocs.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use PHPStan\Type\Generic\TemplateTypeMap;
use PHPStan\Type\Type;

/** @api */
class FunctionVariantWithPhpDocs extends FunctionVariant implements ParametersAcceptorWithPhpDocs
{

Expand All @@ -13,6 +14,7 @@ class FunctionVariantWithPhpDocs extends FunctionVariant implements ParametersAc
private Type $nativeReturnType;

/**
* @api
* @param TemplateTypeMap $templateTypeMap
* @param array<int, \PHPStan\Reflection\ParameterReflectionWithPhpDocs> $parameters
* @param bool $isVariadic
Expand Down
1 change: 1 addition & 0 deletions src/Reflection/ParametersAcceptorWithPhpDocs.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use PHPStan\Type\Type;

/** @api */
interface ParametersAcceptorWithPhpDocs extends ParametersAcceptor
{

Expand Down
1 change: 1 addition & 0 deletions src/Reflection/ReflectionWithFilename.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace PHPStan\Reflection;

/** @api */
interface ReflectionWithFilename
{

Expand Down
1 change: 1 addition & 0 deletions src/Type/Constant/ConstantArrayTypeAndMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use PHPStan\TrinaryLogic;
use PHPStan\Type\Type;

/** @api */
class ConstantArrayTypeAndMethod
{

Expand Down
1 change: 1 addition & 0 deletions src/Type/ConstantTypeHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use PHPStan\Type\Constant\ConstantIntegerType;
use PHPStan\Type\Constant\ConstantStringType;

/** @api */
class ConstantTypeHelper
{

Expand Down

0 comments on commit f685968

Please sign in to comment.