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
5 changes: 5 additions & 0 deletions build/PHPStan/Build/NoScopeTypeReadInEngineRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ final class NoScopeTypeReadInEngineRule implements Rule

private const ENGINE_NAMESPACES = [
'PHPStan\\Analyser\\NodeScopeResolver',
'PHPStan\\Analyser\\ArgumentsHandler',
'PHPStan\\Analyser\\AttributesHandler',
'PHPStan\\Analyser\\ClosureProcessor',
'PHPStan\\Analyser\\ParametersProcessor',
'PHPStan\\Analyser\\StatementsHandler',
'PHPStan\\Analyser\\StmtHandler\\',
'PHPStan\\Analyser\\ExprHandler\\',
];
Expand Down
2 changes: 1 addition & 1 deletion src/Analyser/ArgsResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use function sprintf;

/**
* Result of NodeScopeResolver::processArgs(): the scope/throw/impure state after
* Result of ArgumentsHandler::processArgs(): the scope/throw/impure state after
* processing all arguments (wrapped ExpressionResult) plus the ParametersAcceptor
* resolved from the arg types gathered on the arg-to-arg evolving scope. The
* resolved acceptor is type-driven (selectFromTypes) so its generics are resolved
Expand Down
1,260 changes: 1,260 additions & 0 deletions src/Analyser/ArgumentsHandler.php

Large diffs are not rendered by default.

71 changes: 71 additions & 0 deletions src/Analyser/AttributesHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php declare(strict_types = 1);

namespace PHPStan\Analyser;

use PhpParser\Node;
use PhpParser\Node\AttributeGroup;
use PhpParser\Node\Expr\New_;
use PHPStan\DependencyInjection\AutowiredService;
use PHPStan\Reflection\ParametersAcceptorSelector;
use PHPStan\Reflection\ReflectionProvider;

/**
* Processes attribute arguments for NodeScopeResolver - as constructor
* arguments when the attribute class has a constructor, as plain expressions
* otherwise.
*/
#[AutowiredService]
final class AttributesHandler
{

public function __construct(
private ReflectionProvider $reflectionProvider,
private ArgumentsHandler $argumentsHandler,
)
{
}

/**
* @param AttributeGroup[] $attrGroups
* @param callable(Node $node, Scope $scope): void $nodeCallback
*/
public function processAttributeGroups(
NodeScopeResolver $nodeScopeResolver,
Node\Stmt $stmt,
array $attrGroups,
MutatingScope $scope,
ExpressionResultStorage $storage,
callable $nodeCallback,
): void
{
foreach ($attrGroups as $attrGroup) {
foreach ($attrGroup->attrs as $attr) {
$className = $scope->resolveName($attr->name);
if ($this->reflectionProvider->hasClass($className)) {
$classReflection = $this->reflectionProvider->getClass($className);
if ($classReflection->hasConstructor()) {
$constructorReflection = $classReflection->getConstructor();
$parametersAcceptor = ParametersAcceptorSelector::combineVariantsForNormalization(
$attr->args,
$constructorReflection->getVariants(),
$constructorReflection->getNamedArgumentsVariants(),
);
$expr = new New_($attr->name, $attr->args);
$expr = ArgumentsNormalizer::reorderNewArguments($parametersAcceptor, $expr) ?? $expr;
$this->argumentsHandler->processArgs($nodeScopeResolver, $stmt, $constructorReflection, null, $constructorReflection->getVariants(), $constructorReflection->getNamedArgumentsVariants(), $expr, $scope, $storage, $nodeCallback, ExpressionContext::createDeep());
$nodeScopeResolver->callNodeCallback($nodeCallback, $attr, $scope, $storage);
continue;
}
}

foreach ($attr->args as $arg) {
$nodeScopeResolver->processExprNode($stmt, $arg->value, $scope, $storage, $nodeCallback, ExpressionContext::createDeep());
$nodeScopeResolver->callNodeCallback($nodeCallback, $arg, $scope, $storage);
}
$nodeScopeResolver->callNodeCallback($nodeCallback, $attr, $scope, $storage);
}
$nodeScopeResolver->callNodeCallback($nodeCallback, $attrGroup, $scope, $storage);
}
}

}
Loading
Loading