| Methods |
public
|
getFile(): string
When analysing a trait, returns the file where the trait is used,
not the trait file itself. Use getFileDescription() for the trait file path.
When analysing a trait, returns the file where the trait is used,
not the trait file itself. Use getFileDescription() for the trait file path.
Implements
|
#
|
public
|
getFileDescription(): string
For traits, returns the trait file path with the using class context,
e.g. "TraitFile.php (in context of class MyClass)".
For traits, returns the trait file path with the using class context,
e.g. "TraitFile.php (in context of class MyClass)".
Implements
|
#
|
public
|
isDeclareStrictTypes(): bool
|
#
|
public
|
isInClass(): bool
|
#
|
public
|
isInTrait(): bool
|
#
|
public
|
getClassReflection(): ?ClassReflection
|
#
|
public
|
getTraitReflection(): ?ClassReflection
Returns the trait itself, not the class using the trait.
Use getClassReflection() for the using class.
Returns the trait itself, not the class using the trait.
Use getClassReflection() for the using class.
Implements
|
#
|
public
|
getFunction(): ?PhpFunctionFromParserNodeReflection
|
#
|
public
|
getFunctionName(): ?string
|
#
|
public
|
getNamespace(): ?string
|
#
|
public
|
getParentScope(): ?self
|
#
|
public
|
canAnyVariableExist(): bool
True at the top level of a file or after extract() — contexts where
arbitrary variables may exist.
True at the top level of a file or after extract() — contexts where
arbitrary variables may exist.
Implements
|
#
|
public
|
hasVariableType(string $variableName): TrinaryLogic
|
#
|
public
|
getVariableType(string $variableName): Type
|
#
|
public
|
getDefinedVariables(): list<string>
|
#
|
public
|
getMaybeDefinedVariables(): list<string>
Variables with TrinaryLogic::Maybe certainty — defined in some code paths but not others.
Variables with TrinaryLogic::Maybe certainty — defined in some code paths but not others.
Implements
|
#
|
public
|
hasConstant(Name $name): bool
|
#
|
public
|
isInAnonymousFunction(): bool
|
#
|
public
|
getAnonymousFunctionReflection(): ?ClosureType
|
#
|
public
|
getAnonymousFunctionReturnType(): ?Type
|
#
|
public
|
getType(Expr $node): Type
Returns the PHPDoc-enhanced type. Use getNativeType() for native types only.
Returns the PHPDoc-enhanced type. Use getNativeType() for native types only.
Overridden by
Implements
|
#
|
public
|
getNativeType(Expr $expr): Type
Returns only what PHP's native type system knows, ignoring PHPDoc.
Returns only what PHP's native type system knows, ignoring PHPDoc.
Overridden by
Implements
|
#
|
public
|
resolveName(Name $name): string
Resolves a Name AST node to a fully qualified class name string. Handles special names: self and static resolve to the current class,
parent resolves to the parent class. Other names are returned as-is
(they should already be fully qualified by the PHP parser's name resolver). Inside a Closure::bind() context, self/static resolve to the bound class.
Resolves a Name AST node to a fully qualified class name string. Handles special names: self and static resolve to the current class,
parent resolves to the parent class. Other names are returned as-is
(they should already be fully qualified by the PHP parser's name resolver). Inside a Closure::bind() context, self/static resolve to the bound class.
Implements
|
#
|
public
|
resolveTypeByName(Name $name): TypeWithClassName
Resolves a Name AST node to a TypeWithClassName. Unlike resolveName() which returns a plain string, this returns a proper
Type object that preserves late-static-binding information:
static returns a StaticType (preserves LSB in subclasses)
self returns a ThisType when inside the same class hierarchy
- Other names return an ObjectType
Resolves a Name AST node to a TypeWithClassName. Unlike resolveName() which returns a plain string, this returns a proper
Type object that preserves late-static-binding information:
static returns a StaticType (preserves LSB in subclasses)
self returns a ThisType when inside the same class hierarchy
- Other names return an ObjectType
Implements
|
#
|
public
|
getTypeFromValue(mixed $value): Type
Returns the PHPStan Type representing a given PHP value. Converts runtime PHP values to their corresponding constant types:
integers become ConstantIntegerType, strings become ConstantStringType,
arrays become ConstantArrayType (if small enough), etc.
Returns the PHPStan Type representing a given PHP value. Converts runtime PHP values to their corresponding constant types:
integers become ConstantIntegerType, strings become ConstantStringType,
arrays become ConstantArrayType (if small enough), etc.
Implements
|
#
|
public
|
hasExpressionType(Expr $node): TrinaryLogic
Returns whether an expression has a tracked type in this scope. Returns TrinaryLogic::Yes if the expression's type is definitely known,
TrinaryLogic::Maybe if it might be known, and TrinaryLogic::No if there
is no type information for it. This checks the scope's expression type map without computing the type
(unlike getType() which always computes a type).
Returns whether an expression has a tracked type in this scope. Returns TrinaryLogic::Yes if the expression's type is definitely known,
TrinaryLogic::Maybe if it might be known, and TrinaryLogic::No if there
is no type information for it. This checks the scope's expression type map without computing the type
(unlike getType() which always computes a type).
Implements
|
#
|
public
|
isInClassExists(string $className): bool
Returns whether the given class name is being checked inside a
class_exists(), interface_exists(), or trait_exists() call. When true, rules should suppress "class not found" errors because
the code is explicitly checking for the class's existence.
Returns whether the given class name is being checked inside a
class_exists(), interface_exists(), or trait_exists() call. When true, rules should suppress "class not found" errors because
the code is explicitly checking for the class's existence.
Implements
|
#
|
public
|
isInFunctionExists(string $functionName): bool
Returns whether the given function name is being checked inside a
function_exists() call. When true, rules should suppress "function not found" errors because
the code is explicitly checking for the function's existence.
Returns whether the given function name is being checked inside a
function_exists() call. When true, rules should suppress "function not found" errors because
the code is explicitly checking for the function's existence.
Implements
|
#
|
public
|
enterClass(ClassReflection $classReflection): self
|
#
|
public
|
enterClassMethod(
ClassMethod $classMethod,
TemplateTypeMap $templateTypeMap,
Type[] $phpDocParameterTypes,
?Type $phpDocReturnType,
?Type $throwType,
?string $deprecatedDescription,
bool $isDeprecated,
bool $isInternal,
bool $isFinal,
?bool $isPure = null,
bool $acceptsNamedArguments = true,
?Assertions $asserts = null,
?Type $selfOutType = null,
?string $phpDocComment = null,
Type[] $parameterOutTypes = [],
array<string, bool> $immediatelyInvokedCallableParameters = [],
array<string, Type> $phpDocClosureThisTypeParameters = [],
bool $isConstructor = false,
?ResolvedPhpDocBlock $resolvedPhpDocBlock = null,
): self
|
#
|
public
|
enterFunction(
Function_ $function,
TemplateTypeMap $templateTypeMap,
Type[] $phpDocParameterTypes,
?Type $phpDocReturnType,
?Type $throwType,
?string $deprecatedDescription,
bool $isDeprecated,
bool $isInternal,
?bool $isPure = null,
bool $acceptsNamedArguments = true,
?Assertions $asserts = null,
?string $phpDocComment = null,
Type[] $parameterOutTypes = [],
array<string, bool> $immediatelyInvokedCallableParameters = [],
array<string, Type> $phpDocClosureThisTypeParameters = [],
): self
|
#
|
public
|
enterNamespace(string $namespaceName): self
|
#
|
public
|
isInClosureBind(): bool
Returns whether the current analysis context is inside a Closure::bind()
or Closure::bindTo() call. When true, the closure's $this and self/static may refer to a different
class than the one where the closure was defined.
Returns whether the current analysis context is inside a Closure::bind()
or Closure::bindTo() call. When true, the closure's $this and self/static may refer to a different
class than the one where the closure was defined.
Implements
|
#
|
public
|
enterAnonymousFunction(Closure $closure, ParameterReflection[]|null $callableParameters): self
|
#
|
public
|
enterArrowFunction(ArrowFunction $arrowFunction, ParameterReflection[]|null $callableParameters): self
|
#
|
public
|
getFunctionType(Name|Identifier|ComplexType|null $type, bool $isNullable, bool $isVariadic): Type
Resolves a type AST node (from a parameter/return type declaration) to a Type. Handles named types, identifier types (int, string, etc.), union types,
intersection types, and nullable types. The $isNullable flag adds null
to the type, and $isVariadic wraps the type in an array.
Resolves a type AST node (from a parameter/return type declaration) to a Type. Handles named types, identifier types (int, string, etc.), union types,
intersection types, and nullable types. The $isNullable flag adds null
to the type, and $isVariadic wraps the type in an array.
Implements
|
#
|
public
|
isInExpressionAssign(Expr $expr): bool
Returns whether the given expression is currently being assigned to. Returns true during the analysis of the right-hand side of an assignment
to this expression. For example, when analysing $a = expr, this returns
true for the $a variable during the analysis of expr. Used to prevent infinite recursion when resolving types during assignment.
Returns whether the given expression is currently being assigned to. Returns true during the analysis of the right-hand side of an assignment
to this expression. For example, when analysing $a = expr, this returns
true for the $a variable during the analysis of expr. Used to prevent infinite recursion when resolving types during assignment.
Implements
|
#
|
public
|
isUndefinedExpressionAllowed(Expr $expr): bool
Returns whether accessing the given expression in an undefined state is allowed. Returns true when the expression is on the left-hand side of an assignment
or in similar contexts where it's valid for the expression to be undefined
(e.g. $a['key'] = value where $a['key'] doesn't need to exist yet).
Returns whether accessing the given expression in an undefined state is allowed. Returns true when the expression is on the left-hand side of an assignment
or in similar contexts where it's valid for the expression to be undefined
(e.g. $a['key'] = value where $a['key'] doesn't need to exist yet).
Implements
|
#
|
public
|
filterByTruthyValue(Expr $expr): self
Returns a new Scope with types narrowed by assuming the expression is truthy. Given an expression like $x instanceof Foo, returns a scope where
$x is known to be of type Foo. This is the scope used inside the
if-branch of if ($x instanceof Foo). Uses the TypeSpecifier internally to determine type narrowing.
Returns a new Scope with types narrowed by assuming the expression is truthy. Given an expression like $x instanceof Foo, returns a scope where
$x is known to be of type Foo. This is the scope used inside the
if-branch of if ($x instanceof Foo). Uses the TypeSpecifier internally to determine type narrowing.
Implements
|
#
|
public
|
filterByFalseyValue(Expr $expr): self
Returns a new Scope with types narrowed by assuming the expression is falsy. The opposite of filterByTruthyValue(). Given $x instanceof Foo, returns
a scope where $x is known NOT to be of type Foo. This is the scope used
in the else-branch of if ($x instanceof Foo).
Returns a new Scope with types narrowed by assuming the expression is falsy. The opposite of filterByTruthyValue(). Given $x instanceof Foo, returns
a scope where $x is known NOT to be of type Foo. This is the scope used
in the else-branch of if ($x instanceof Foo).
Implements
|
#
|
public
|
isInFirstLevelStatement(): bool
Returns whether the current statement is a "first-level" statement. A first-level statement is one that is directly inside a function/method
body, not nested inside control structures like if/else, loops, or
try/catch. Used to determine whether certain checks should be more
or less strict.
Returns whether the current statement is a "first-level" statement. A first-level statement is one that is directly inside a function/method
body, not nested inside control structures like if/else, loops, or
try/catch. Used to determine whether certain checks should be more
or less strict.
Implements
|
#
|
public
|
canAccessProperty(PropertyReflection $propertyReflection): bool
Deprecated
Use canReadProperty() or canWriteProperty()
Implements
|
#
|
public
|
canReadProperty(ExtendedPropertyReflection $propertyReflection): bool
|
#
|
public
|
canWriteProperty(ExtendedPropertyReflection $propertyReflection): bool
|
#
|
public
|
canCallMethod(MethodReflection $methodReflection): bool
|
#
|
public
|
canAccessConstant(ClassConstantReflection $constantReflection): bool
|
#
|
public
|
getMethodReflection(Type $typeWithMethod, string $methodName): ?ExtendedMethodReflection
|
#
|
public
|
getPropertyReflection(Type $typeWithProperty, string $propertyName): ?ExtendedPropertyReflection
Deprecated
Use getInstancePropertyReflection or getStaticPropertyReflection instead
Implements
|
#
|
public
|
getInstancePropertyReflection(Type $typeWithProperty, string $propertyName): ?ExtendedPropertyReflection
|
#
|
public
|
getStaticPropertyReflection(Type $typeWithProperty, string $propertyName): ?ExtendedPropertyReflection
|
#
|