| 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.
Implemented by
|
#
|
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)".
Implemented by
|
#
|
public
|
isDeclareStrictTypes(): bool
|
#
|
public
|
isInTrait(): bool
|
#
|
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.
Implemented by
|
#
|
public
|
getFunction(): ?PhpFunctionFromParserNodeReflection
|
#
|
public
|
getFunctionName(): ?string
|
#
|
public
|
getParentScope(): ?self
|
#
|
public
|
hasVariableType(string $variableName): TrinaryLogic
|
#
|
public
|
getVariableType(string $variableName): Type
|
#
|
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.
Implemented by
|
#
|
public
|
getDefinedVariables(): array<int, string>
|
#
|
public
|
getMaybeDefinedVariables(): array<int, 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.
Implemented by
|
#
|
public
|
hasConstant(Name $name): bool
|
#
|
public
|
getPropertyReflection(Type $typeWithProperty, string $propertyName): ?ExtendedPropertyReflection
Deprecated
Use getInstancePropertyReflection or getStaticPropertyReflection instead
Implemented by
|
#
|
public
|
getInstancePropertyReflection(Type $typeWithProperty, string $propertyName): ?ExtendedPropertyReflection
|
#
|
public
|
getStaticPropertyReflection(Type $typeWithProperty, string $propertyName): ?ExtendedPropertyReflection
|
#
|
public
|
getMethodReflection(Type $typeWithMethod, string $methodName): ?ExtendedMethodReflection
|
#
|
public
|
getConstantReflection(Type $typeWithConstant, string $constantName): ?ClassConstantReflection
|
#
|
public
|
getConstantExplicitTypeFromConfig(string $constantName, Type $constantType): Type
|
#
|
public
|
getIterableKeyType(Type $iteratee): Type
|
#
|
public
|
getIterableValueType(Type $iteratee): Type
|
#
|
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.
Implemented by
|
#
|
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.
Implemented by
|
#
|
public
|
getKeepVoidType(Expr $node): Type
Like getType(), but preserves void for function/method calls
(normally getType() replaces void with null).
Like getType(), but preserves void for function/method calls
(normally getType() replaces void with null).
|
#
|
public
|
getScopeType(Expr $expr): Type
Unlike getType() which may defer evaluation, this uses the scope's
current state immediately.
Unlike getType() which may defer evaluation, this uses the scope's
current state immediately.
|
#
|
public
|
getScopeNativeType(Expr $expr): Type
|
#
|
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.
Implemented by
|
#
|
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
Implemented by
|
#
|
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.
Implemented by
|
#
|
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).
Implemented by
|
#
|
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.
Implemented by
|
#
|
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.
Implemented by
|
#
|
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.
Implemented by
|
#
|
public
|
getFunctionCallStack(): list<FunctionReflection|MethodReflection>
Returns the stack of function/method calls that are currently being analysed. When analysing arguments of a function call, this returns the chain of
enclosing calls. Used by extensions that need to know the calling context,
such as type-specifying extensions for functions like class_exists().
Returns the stack of function/method calls that are currently being analysed. When analysing arguments of a function call, this returns the chain of
enclosing calls. Used by extensions that need to know the calling context,
such as type-specifying extensions for functions like class_exists().
|
#
|
public
|
getFunctionCallStackWithParameters(): list<array{(FunctionReflection|MethodReflection), (ParameterReflection|null)}>
Like getFunctionCallStack(), but also includes the parameter being passed to. Each entry is a tuple of the function/method reflection and the parameter
reflection for the argument position being analysed (or null if unknown).
Like getFunctionCallStack(), but also includes the parameter being passed to. Each entry is a tuple of the function/method reflection and the parameter
reflection for the argument position being analysed (or null if unknown).
|
#
|
public
|
isParameterValueNullable(Param $parameter): bool
Returns whether a function parameter has a default value of null. Checks the parameter's default value AST node to determine if
= null was specified. Used by function definition checks.
Returns whether a function parameter has a default value of null. Checks the parameter's default value AST node to determine if
= null was specified. Used by function definition checks.
|
#
|
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.
Implemented by
|
#
|
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.
Implemented by
|
#
|
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).
Implemented by
|
#
|
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.
Implemented by
|
#
|
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).
Implemented by
|
#
|
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.
Implemented by
|
#
|
public
|
getPhpVersion(): PhpVersions
Returns the PHP version(s) being analysed against. Returns a PhpVersions object that can represent a range of PHP versions
(when the exact version is not known). Use its methods like
supportsEnums(), supportsReadonlyProperties(), etc. to check for
version-specific features.
Returns the PHP version(s) being analysed against. Returns a PhpVersions object that can represent a range of PHP versions
(when the exact version is not known). Use its methods like
supportsEnums(), supportsReadonlyProperties(), etc. to check for
version-specific features.
|
#
|