Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions e2e/result-cache-file-dependency/extension/ConfigRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use PhpParser\Node;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Name;
use PHPStan\Analyser\DependencyEmitter;
use PHPStan\Analyser\DependencyTracker;
use PHPStan\Analyser\Scope;
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleErrorBuilder;
Expand All @@ -25,7 +25,7 @@ public function getNodeType(): string
}

/**
* @param Scope&DependencyEmitter $scope
* @param Scope&DependencyTracker $scope
*/
public function processNode(Node $node, Scope $scope): array
{
Expand All @@ -34,7 +34,7 @@ public function processNode(Node $node, Scope $scope): array
}

$configFile = dirname(__DIR__) . '/src/Config.php';
$scope->fileDependency($configFile);
$scope->trackFileDependency($configFile);

if (!is_file($configFile)) {
return [];
Expand Down
6 changes: 3 additions & 3 deletions e2e/result-cache-file-dependency/extension/DataFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace ResultCacheE2EFileDependency;

use PHPStan\Analyser\DependencyEmitter;
use PHPStan\Analyser\DependencyTracker;
use PHPStan\Analyser\Scope;
use PHPStan\Type\Constant\ConstantStringType;
use PHPStan\Type\IntegerType;
Expand All @@ -15,12 +15,12 @@ final class DataFile
* The return type comes from a data file the extension reads on its own: int when it says so,
* otherwise the string it contains, 'missing' when there is no such file.
*
* @param Scope&DependencyEmitter $scope
* @param Scope&DependencyTracker $scope
*/
public static function type(string $name, Scope $scope): Type
{
$file = dirname(__DIR__) . '/data/' . $name . '.txt';
$scope->fileDependency($file);
$scope->trackFileDependency($file);

if (!is_file($file)) {
return new ConstantStringType('missing');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace ResultCacheE2EFileDependency;

use PhpParser\Node\Expr\FuncCall;
use PHPStan\Analyser\DependencyEmitter;
use PHPStan\Analyser\DependencyTracker;
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\FunctionReflection;
use PHPStan\Type\DynamicFunctionReturnTypeExtension;
Expand All @@ -18,7 +18,7 @@ public function isFunctionSupported(FunctionReflection $functionReflection): boo
}

/**
* @param Scope&DependencyEmitter $scope
* @param Scope&DependencyTracker $scope
*/
public function getTypeFromFunctionCall(FunctionReflection $functionReflection, FuncCall $functionCall, Scope $scope): Type
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace ResultCacheE2EFileDependency;

use PhpParser\Node\Expr\MethodCall;
use PHPStan\Analyser\DependencyEmitter;
use PHPStan\Analyser\DependencyTracker;
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\MethodReflection;
use PHPStan\Type\DynamicMethodReturnTypeExtension;
Expand All @@ -23,7 +23,7 @@ public function isMethodSupported(MethodReflection $methodReflection): bool
}

/**
* @param Scope&DependencyEmitter $scope
* @param Scope&DependencyTracker $scope
*/
public function getTypeFromMethodCall(MethodReflection $methodReflection, MethodCall $methodCall, Scope $scope): Type
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace ResultCacheE2EFileDependency;

use PhpParser\Node\Expr\StaticCall;
use PHPStan\Analyser\DependencyEmitter;
use PHPStan\Analyser\DependencyTracker;
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\MethodReflection;
use PHPStan\Type\DynamicStaticMethodReturnTypeExtension;
Expand All @@ -23,7 +23,7 @@ public function isStaticMethodSupported(MethodReflection $methodReflection): boo
}

/**
* @param Scope&DependencyEmitter $scope
* @param Scope&DependencyTracker $scope
*/
public function getTypeFromStaticMethodCall(MethodReflection $methodReflection, StaticCall $methodCall, Scope $scope): Type
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Scalar\String_;
use PHPStan\Analyser\DependencyEmitter;
use PHPStan\Analyser\DependencyTracker;
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\FunctionReflection;
use PHPStan\Type\Constant\ConstantIntegerType;
Expand All @@ -21,7 +21,7 @@ public function isFunctionSupported(FunctionReflection $functionReflection): boo
}

/**
* @param Scope&DependencyEmitter $scope
* @param Scope&DependencyTracker $scope
*/
public function getTypeFromFunctionCall(FunctionReflection $functionReflection, FuncCall $functionCall, Scope $scope): ?Type
{
Expand All @@ -30,7 +30,7 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection,
return null;
}

$scope->valueDependency(ParameterValueExtension::class, $arg->value);
$scope->trackValueDependency(ParameterValueExtension::class, $arg->value);
$value = Container::getParameter($arg->value);
if ($value === null) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Scalar\String_;
use PHPStan\Analyser\DependencyEmitter;
use PHPStan\Analyser\DependencyTracker;
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\FunctionReflection;
use PHPStan\Type\DynamicFunctionReturnTypeExtension;
Expand All @@ -20,7 +20,7 @@ public function isFunctionSupported(FunctionReflection $functionReflection): boo
}

/**
* @param Scope&DependencyEmitter $scope
* @param Scope&DependencyTracker $scope
*/
public function getTypeFromFunctionCall(FunctionReflection $functionReflection, FuncCall $functionCall, Scope $scope): ?Type
{
Expand All @@ -30,7 +30,7 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection,
}

// the same value ServiceRule declares - recorded once
$scope->valueDependency(HasServiceValueExtension::class, $arg->value);
$scope->trackValueDependency(HasServiceValueExtension::class, $arg->value);
$class = Container::getService($arg->value);

return $class !== null ? new ObjectType($class) : null;
Expand Down
6 changes: 3 additions & 3 deletions e2e/result-cache-value-dependency/extension/ServiceRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Name;
use PhpParser\Node\Scalar\String_;
use PHPStan\Analyser\DependencyEmitter;
use PHPStan\Analyser\DependencyTracker;
use PHPStan\Analyser\Scope;
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleErrorBuilder;
Expand All @@ -23,7 +23,7 @@ public function getNodeType(): string
}

/**
* @param Scope&DependencyEmitter $scope
* @param Scope&DependencyTracker $scope
*/
public function processNode(Node $node, Scope $scope): array
{
Expand All @@ -32,7 +32,7 @@ public function processNode(Node $node, Scope $scope): array
}

$id = $node->getArgs()[0]->value->value;
$scope->valueDependency(HasServiceValueExtension::class, $id);
$scope->trackValueDependency(HasServiceValueExtension::class, $id);
if (Container::getService($id) !== null) {
return [];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,34 @@
use PHPStan\Analyser\ResultCache\ResultCacheValueExtension;

/**
* The interface DependencyEmitter can be typehinted in 2nd parameter of Rule::processNode(),
* The interface DependencyTracker can be typehinted in 2nd parameter of Rule::processNode(),
* and in the Scope parameter of dynamic return type extensions and expression type resolver
* extensions:
*
* ```php
* /**
* * @param Scope&DependencyEmitter $scope
* * @param Scope&DependencyTracker $scope
* *\/
* public function processNode(Node $node, Scope $scope): array
* ```
*
* The intersection goes to the PHPDoc: the native parameter type stays Scope, which is what the
* interfaces declare once PHPStan is downgraded for older PHP versions.
*
* It declares 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.
* 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.
*
* @api
*/
interface DependencyEmitter
interface DependencyTracker
{

/**
* The analysis of the current file depends on the value $extensionClass gives for $key.
*
* @param class-string<ResultCacheValueExtension> $extensionClass
*/
public function valueDependency(string $extensionClass, string $key): void;
public function trackValueDependency(string $extensionClass, string $key): void;

/**
* The analysis of the current file depends on the contents of $file - a data file, a template,
Expand All @@ -41,6 +41,6 @@ public function valueDependency(string $extensionClass, string $key): void;
*
* The path should be absolute. The file does not have to exist.
*/
public function fileDependency(string $file): void;
public function trackFileDependency(string $file): void;

}
6 changes: 3 additions & 3 deletions src/Analyser/FileAnalyserCallback.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function __invoke(Node $node, Scope $scope): void

$parserNodes = $this->parserNodes;

/** @var Scope&NodeCallbackInvoker&CollectedDataEmitter&DependencyEmitter $scope */
/** @var Scope&NodeCallbackInvoker&CollectedDataEmitter&DependencyTracker $scope */
if ($node instanceof Node\Stmt\Trait_) {
foreach (array_keys($this->linesToIgnore[$this->file] ?? []) as $lineToIgnore) {
if ($lineToIgnore < $node->getStartLine() || $lineToIgnore > $node->getEndLine()) {
Expand Down Expand Up @@ -182,9 +182,9 @@ public function __invoke(Node $node, Scope $scope): void

foreach ($ruleErrors as $ruleError) {
if ($ruleError instanceof FileDependenciesRuleError) {
// the deprecated way of DependencyEmitter::fileDependency()
// the deprecated way of DependencyTracker::trackFileDependency()
foreach ($ruleError->getFileDependencies() as $fileDependency) {
$scope->fileDependency($fileDependency);
$scope->trackFileDependency($fileDependency);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/Analyser/MutatingScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@
use const PHP_INT_MIN;

#[ShadowedByTurboExtension(implementation: __DIR__ . '/../../turbo-ext/src/MutatingScope.cpp')]
class MutatingScope implements Scope, NodeCallbackInvoker, CollectedDataEmitter, DependencyEmitter
class MutatingScope implements Scope, NodeCallbackInvoker, CollectedDataEmitter, DependencyTracker
{

private const COMPLEX_UNION_TYPE_MEMBER_LIMIT = 8;
Expand Down Expand Up @@ -6071,13 +6071,13 @@ public function emitCollectedData(string $collectorType, mixed $data): void
$nodeCallback(new EmitCollectedDataNode($collectorType, $data), $this);
}

public function valueDependency(string $extensionClass, string $key): void
public function trackValueDependency(string $extensionClass, string $key): void
{
// a scope without a node callback is outside the walk of the analysed file - see ValueDependencyCollector
$this->container->getByType(ValueDependencyCollector::class)->record($extensionClass, $key, $this, $this->nodeCallback !== null);
}

public function fileDependency(string $file): void
public function trackFileDependency(string $file): void
{
$this->container->getByType(ValueDependencyCollector::class)->recordFile($file, $this, $this->nodeCallback !== null);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Analyser/ResultCache/FileResultCacheValueExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use PHPStan\File\FileContentHasher;

/**
* The value behind DependencyEmitter::fileDependency(): the hash of the file's contents, or that
* The value behind DependencyTracker::trackFileDependency(): the hash of the file's contents, or that
* the file does not exist. Any change of the file - also its creation or deletion - re-analyses the
* files depending on it, whatever happened to what it declares.
*
Expand Down
2 changes: 1 addition & 1 deletion src/Analyser/ResultCache/ResultCacheManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,7 @@ public function restore(array $allAnalysedFiles, bool $debug, bool $onlyFiles, ?
);
}

// The values declared through DependencyEmitter::valueDependency() - see ValueDependencyCollector.
// The values declared through DependencyTracker::trackValueDependency() - see ValueDependencyCollector.
// The files depending on one that is different now are re-analysed, and so are the ones
// depending on one whose extension is no longer registered, which is then forgotten.
$allAnalysedFilesSet = array_fill_keys($allAnalysedFiles, true);
Expand Down
2 changes: 1 addition & 1 deletion src/Analyser/ResultCache/ResultCacheValueExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* A rule or an extension reading such a value declares it:
*
* ```php
* $scope->valueDependency(MyExtension::class, $key);
* $scope->trackValueDependency(MyExtension::class, $key);
* ```
*
* The result cache then records the value, and re-analyses the files that declared it when it
Expand Down
4 changes: 2 additions & 2 deletions src/Analyser/ValueDependencyCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use function sprintf;

/**
* Collects the values declared through DependencyEmitter::valueDependency() while a file is being
* Collects the values declared through DependencyTracker::trackValueDependency() while a file is being
* analysed, and what each value was at that moment - the value the analysis saw.
*
* A value is identified by its extension and key: the same one declared again, by the same rule
Expand Down Expand Up @@ -104,7 +104,7 @@ public function record(string $extensionClass, string $key, Scope $scope, bool $
}

/**
* DependencyEmitter::fileDependency() - a dependency on the contents of a file, through
* DependencyTracker::trackFileDependency() - a dependency on the contents of a file, through
* FileResultCacheValueExtension.
*/
public function recordFile(string $file, Scope $scope, bool $insideWalk): void
Expand Down
6 changes: 3 additions & 3 deletions src/Rules/Keywords/RequireFileExistsRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\Include_;
use PhpParser\Node\Name\FullyQualified;
use PHPStan\Analyser\DependencyEmitter;
use PHPStan\Analyser\DependencyTracker;
use PHPStan\Analyser\Scope;
use PHPStan\DependencyInjection\AutowiredParameter;
use PHPStan\DependencyInjection\RegisteredRule;
Expand Down Expand Up @@ -59,7 +59,7 @@ public function getNodeType(): string
return Include_::class;
}

public function processNode(Node $node, Scope&DependencyEmitter $scope): array
public function processNode(Node $node, Scope&DependencyTracker $scope): array
{
if ($this->isInFileExists($node, $scope)) {
return [];
Expand All @@ -85,7 +85,7 @@ public function processNode(Node $node, Scope&DependencyEmitter $scope): array
// The error is about a path, and a path is nothing the dependency graph tracks. Declaring the
// paths makes the result cache re-analyse this file when one of them is created.
foreach ($this->includedFilePathResolver->resolve($path, $scope) as $candidatePath) {
$scope->fileDependency($candidatePath);
$scope->trackFileDependency($candidatePath);
}

$errors[] = $this->getErrorMessage($node, $pathExpr);
Expand Down
6 changes: 3 additions & 3 deletions src/Rules/Methods/OverridingMethodRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use PhpParser\Node;
use PhpParser\Node\Attribute;
use PHPStan\Analyser\CollectedDataEmitter;
use PHPStan\Analyser\DependencyEmitter;
use PHPStan\Analyser\DependencyTracker;
use PHPStan\Analyser\NodeCallbackInvoker;
use PHPStan\Analyser\Scope;
use PHPStan\DependencyInjection\AutowiredParameter;
Expand Down Expand Up @@ -53,7 +53,7 @@ public function getNodeType(): string
return InClassMethodNode::class;
}

public function processNode(Node $node, Scope&NodeCallbackInvoker&CollectedDataEmitter&DependencyEmitter $scope): array
public function processNode(Node $node, Scope&NodeCallbackInvoker&CollectedDataEmitter&DependencyTracker $scope): array
{
$method = $node->getMethodReflection();
$prototypeData = $this->methodPrototypeFinder->findPrototype($node->getClassReflection(), $method->getName());
Expand Down Expand Up @@ -366,7 +366,7 @@ private function filterOverrideAttribute(array $attrGroups): array
private function addErrors(
array $errors,
InClassMethodNode $classMethod,
Scope&NodeCallbackInvoker&CollectedDataEmitter&DependencyEmitter $scope,
Scope&NodeCallbackInvoker&CollectedDataEmitter&DependencyTracker $scope,
): array
{
if (count($errors) > 0) {
Expand Down
4 changes: 2 additions & 2 deletions src/Rules/Playground/PromoteParameterRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use PhpParser\Node;
use PHPStan\Analyser\CollectedDataEmitter;
use PHPStan\Analyser\DependencyEmitter;
use PHPStan\Analyser\DependencyTracker;
use PHPStan\Analyser\NodeCallbackInvoker;
use PHPStan\Analyser\Scope;
use PHPStan\DependencyInjection\Container;
Expand Down Expand Up @@ -89,7 +89,7 @@ private function getOriginalRule(): ?Rule
return $this->originalRule = $originalRule;
}

public function processNode(Node $node, Scope&NodeCallbackInvoker&CollectedDataEmitter&DependencyEmitter $scope): array
public function processNode(Node $node, Scope&NodeCallbackInvoker&CollectedDataEmitter&DependencyTracker $scope): array
{
if ($this->parameterValue) {
return [];
Expand Down
Loading
Loading