| 1: | <?php declare(strict_types = 1); |
| 2: | |
| 3: | namespace PHPStan\Analyser; |
| 4: | |
| 5: | use PHPStan\Analyser\ResultCache\ResultCacheValueExtension; |
| 6: | |
| 7: | /** |
| 8: | * The interface DependencyTracker can be typehinted in 2nd parameter of Rule::processNode() and |
| 9: | * Collector::processNode(), and in the Scope parameter of dynamic return type extensions, dynamic |
| 10: | * throw type extensions, expression type resolver extensions, parameter out type extensions, |
| 11: | * parameter closure type extensions, parameter closure this extensions and type-specifying |
| 12: | * extensions: |
| 13: | * |
| 14: | * ```php |
| 15: | * /** |
| 16: | * * @param Scope&DependencyTracker $scope |
| 17: | * *\/ |
| 18: | * public function processNode(Node $node, Scope $scope): array |
| 19: | * ``` |
| 20: | * |
| 21: | * The intersection goes to the PHPDoc: the native parameter type stays Scope, which is what the |
| 22: | * interfaces declare once PHPStan is downgraded for older PHP versions. |
| 23: | * |
| 24: | * It tracks what the analysis of the current file depends on besides the analysed code, so that |
| 25: | * the result cache re-analyses the file when that changes - see ResultCacheValueExtension. |
| 26: | * |
| 27: | * Extensions that get no Scope because they describe a class - class reflection extensions - use |
| 28: | * DeclarationDependencyTracker instead. |
| 29: | * |
| 30: | * @api |
| 31: | */ |
| 32: | interface DependencyTracker |
| 33: | { |
| 34: | |
| 35: | /** |
| 36: | * The analysis of the current file depends on the value $extensionClass gives for $key. |
| 37: | * |
| 38: | * @param class-string<ResultCacheValueExtension> $extensionClass |
| 39: | */ |
| 40: | public function trackValueDependency(string $extensionClass, string $key): void; |
| 41: | |
| 42: | /** |
| 43: | * The analysis of the current file depends on the contents of $file - a data file, a template, |
| 44: | * a docblock in another PHP file - that is read on its own, without PHPStan knowing about it. |
| 45: | * The current file is then re-analysed whenever $file is created, changed in any way, or deleted. |
| 46: | * |
| 47: | * The path should be absolute. The file does not have to exist. |
| 48: | */ |
| 49: | public function trackFileDependency(string $file): void; |
| 50: | |
| 51: | /** |
| 52: | * The analysis of the current file depends on the files in $directory, recursively, whose names |
| 53: | * match $pattern (fnmatch() syntax, like "*.php" or "Pest.php") - a directory scanned for |
| 54: | * configuration files, templates or migrations. The current file is then re-analysed whenever such |
| 55: | * a file is created, changed in any way, deleted or renamed, or the directory itself is created or |
| 56: | * deleted. |
| 57: | */ |
| 58: | public function trackDirectoryDependency(string $directory, string $pattern = '*'): void; |
| 59: | |
| 60: | /** |
| 61: | * The analysis of the current file depends on the class $className as if the code referenced it - |
| 62: | * a class named in a string, in a PHPDoc tag PHPStan does not resolve, or in a configuration file. |
| 63: | * The current file is then re-analysed when the class or one of its parents, interfaces or traits |
| 64: | * changes what it declares (signatures and PHPDocs, not method bodies), and when the class is |
| 65: | * created, deleted or moved to another file. |
| 66: | */ |
| 67: | public function trackClassDependency(string $className): void; |
| 68: | |
| 69: | } |
| 70: |