Namespace PHPStan\Analyser

Classes
ArgumentsNormalizer
EndStatementResult
Error
ImpurePoint
InternalError
MutatingScope
NameScope
NodeCallbackScope
NodeScopeResolver
OutOfClassScope
ScopeContext
ScopeFactory
SpecifiedTypes
StatementContext

Object of this class is one of the parameters of NodeScopeResolver::processStmtNodes(). It determines whether loops will be analysed once or multiple times until the types "stabilize". When in doubt, use StatementContext::createTopLevel().

StatementExitPoint
StatementResult
ThrowPoint
TypeSpecifier
TypeSpecifierContext
Interfaces
CollectedDataEmitter

The interface CollectedDataEmitter can be typehinted in 2nd parameter of Rule::processNode(): ```php public function processNode(Node $node, Scope&CollectedDataEmitter $scope): array

a separate complex Collector class. The emitted data is aggregated the same way
as data from Collectors and can be consumed by rules registered
for CollectedDataNode. The actual MyCollector class in the example has to exist, to verify
the data type statically, and to identify the collected data. The referenced MyCollector class should NOT be registered
as a collector, unless you also want it to collect data on its own. ```php
$scope->emitCollectedData(MyCollector::class, ['some', 'data']);
DeclarationDependencyTracker

DependencyTracker for extensions that get no Scope because they describe a class rather than analyse code - class reflection extensions adding magic methods and properties, for example. Inject it into the extension's constructor. What PHPStan learns about a class this way is remembered and reused by every file analysed after it, so it's the class that depends on what the extension read, not the file being analysed: each method declares the dependency of $classReflection. When it changes, every file depending on the class - referencing it, calling its methods, reading its properties - is analysed again.

DependencyTracker

The interface DependencyTracker can be typehinted in 2nd parameter of Rule::processNode() and Collector::processNode(), and in the Scope parameter of dynamic return type extensions, dynamic throw type extensions, expression type resolver extensions, parameter out type extensions, parameter closure type extensions, parameter closure this extensions and type-specifying extensions: ```php /**

  • @param Scope&DependencyTracker $scope */ public function processNode(Node $node, Scope $scope): array
interfaces declare once PHPStan is downgraded for older PHP versions. It tracks what the analysis of the current file depends on besides the analysed code, so that
the result cache re-analyses the file when that changes - see ResultCacheValueExtension. Extensions that get no Scope because they describe a class - class reflection extensions - use
DeclarationDependencyTracker instead.
IgnoreErrorExtension

This is the extension interface to implement if you want to ignore errors based on the node and scope. To register it in the configuration file use the phpstan.ignoreErrorExtension service tag: ``` services: - class: App\PHPStan\MyExtension tags: - phpstan.ignoreErrorExtension

NodeCallbackInvoker

The interface NodeCallbackInvoker can be typehinted in 2nd parameter of Rule::processNode(): php public function processNode(Node $node, Scope&NodeCallbackInvoker $scope): array It can be used to invoke rules for virtual made-up nodes. For example: You're writing a rule for a method with declaration like: php public static create(string $class, mixed ...$args) And you'd like to check Factory::create(Foo::class, 1, 2, 3) as if it were new Foo(1, 2, 3). You can call $scope->invokeNodeCallback(new New_(new Name($className), $args)) And PHPStan will call all the registered rules for New_, checking as if the instantiation is actually in the code.

Scope

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.
TypeSpecifierAwareExtension
Exceptions
UndefinedVariableException
Namespaces
PHPStan\Analyser\ResultCache