Interface PHPStan\Analyser\Scope

extends ClassMemberAccessAnswerer, NamespaceAnswerer

Represents the state of the analyser at a specific position in the AST. The Scope tracks everything PHPStan knows at a given point in code: variable types, the current class/function/method context, whether strict_types is enabled, and more. It is the primary interface through which rules and extensions query information about the analysed code. The Scope is passed as a parameter to:

  • Custom rules (2nd parameter of processNode())
  • Dynamic return type extensions (last parameter of getTypeFrom*Call())
  • Dynamic throw type extensions
  • Type-specifying extensions (3rd parameter of specifyTypes()) The Scope is immutable from the extension's perspective. Each AST node gets its own Scope reflecting the analysis state at that point. For example, after an if ($x instanceof Foo) check, the Scope inside the if-branch knows that $x is of type Foo.
Methods
Methods inherited from PHPStan\Reflection\ClassMemberAccessAnswerer
isInClass(), getClassReflection(), canAccessProperty(), canReadProperty(), canWriteProperty(), canCallMethod(), canAccessConstant()
Methods inherited from PHPStan\Reflection\NamespaceAnswerer
getNamespace()