Skip to content

Commit 52fd1e8

Browse files
committed
Add pureUnlessCallableIsImpureParameters
1 parent 7fc8bdf commit 52fd1e8

File tree

5 files changed

+17
-4
lines changed

5 files changed

+17
-4
lines changed

src/Analyser/MutatingScope.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2932,6 +2932,7 @@ public function enterTrait(ClassReflection $traitReflection): self
29322932
* @param Type[] $parameterOutTypes
29332933
* @param array<string, bool> $immediatelyInvokedCallableParameters
29342934
* @param array<string, Type> $phpDocClosureThisTypeParameters
2935+
* @param array<string, bool> $phpDocPureUnlessCallableIsImpureParameters
29352936
*/
29362937
public function enterClassMethod(
29372938
Node\Stmt\ClassMethod $classMethod,
@@ -2951,6 +2952,7 @@ public function enterClassMethod(
29512952
array $parameterOutTypes = [],
29522953
array $immediatelyInvokedCallableParameters = [],
29532954
array $phpDocClosureThisTypeParameters = [],
2955+
array $phpDocPureUnlessCallableIsImpureParameters = [],
29542956
): self
29552957
{
29562958
if (!$this->isInClass()) {
@@ -2981,6 +2983,7 @@ public function enterClassMethod(
29812983
array_map(fn (Type $type): Type => $this->transformStaticType(TemplateTypeHelper::toArgument($type)), $parameterOutTypes),
29822984
$immediatelyInvokedCallableParameters,
29832985
array_map(fn (Type $type): Type => $this->transformStaticType(TemplateTypeHelper::toArgument($type)), $phpDocClosureThisTypeParameters),
2986+
$phpDocPureUnlessCallableIsImpureParameters,
29842987
),
29852988
!$classMethod->isStatic(),
29862989
);
@@ -3050,6 +3053,7 @@ private function getRealParameterDefaultValues(Node\FunctionLike $functionLike):
30503053
* @param Type[] $parameterOutTypes
30513054
* @param array<string, bool> $immediatelyInvokedCallableParameters
30523055
* @param array<string, Type> $phpDocClosureThisTypeParameters
3056+
* @param array<string, bool> $pureUnlessCallableIsImpureParameters
30533057
*/
30543058
public function enterFunction(
30553059
Node\Stmt\Function_ $function,
@@ -3067,6 +3071,7 @@ public function enterFunction(
30673071
array $parameterOutTypes = [],
30683072
array $immediatelyInvokedCallableParameters = [],
30693073
array $phpDocClosureThisTypeParameters = [],
3074+
array $pureUnlessCallableIsImpureParameters = [],
30703075
): self
30713076
{
30723077
return $this->enterFunctionLike(
@@ -3090,6 +3095,7 @@ public function enterFunction(
30903095
array_map(static fn (Type $type): Type => TemplateTypeHelper::toArgument($type), $parameterOutTypes),
30913096
$immediatelyInvokedCallableParameters,
30923097
$phpDocClosureThisTypeParameters,
3098+
$pureUnlessCallableIsImpureParameters,
30933099
),
30943100
false,
30953101
);

src/Analyser/NodeScopeResolver.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ private function processStmtNode(
599599
$throwPoints = [];
600600
$impurePoints = [];
601601
$this->processAttributeGroups($stmt, $stmt->attrGroups, $scope, $nodeCallback);
602-
[$templateTypeMap, $phpDocParameterTypes, $phpDocImmediatelyInvokedCallableParameters, $phpDocClosureThisTypeParameters, $phpDocReturnType, $phpDocThrowType, $deprecatedDescription, $isDeprecated, $isInternal, $isFinal, $isPure, $acceptsNamedArguments, , $phpDocComment, $asserts, $selfOutType, $phpDocParameterOutTypes] = $this->getPhpDocs($scope, $stmt);
602+
[$templateTypeMap, $phpDocParameterTypes, $phpDocImmediatelyInvokedCallableParameters, $phpDocClosureThisTypeParameters, $phpDocReturnType, $phpDocThrowType, $deprecatedDescription, $isDeprecated, $isInternal, $isFinal, $isPure, $acceptsNamedArguments, , $phpDocComment, $asserts, $selfOutType, $phpDocParameterOutTypes, $pureUnlessCallableIsImpureParameters] = $this->getPhpDocs($scope, $stmt);
603603

604604
foreach ($stmt->params as $param) {
605605
$this->processParamNode($stmt, $param, $scope, $nodeCallback);
@@ -6000,7 +6000,7 @@ private function processNodesForCalledMethod($node, string $fileName, MethodRefl
60006000
}
60016001

60026002
/**
6003-
* @return array{TemplateTypeMap, array<string, Type>, array<string, bool>, array<string, Type>, ?Type, ?Type, ?string, bool, bool, bool, bool|null, bool, bool, string|null, Assertions, ?Type, array<string, Type>, array<(string|int), VarTag>, bool}
6003+
* @return array{TemplateTypeMap, array<string, Type>, array<string, bool>, array<string, Type>, ?Type, ?Type, ?string, bool, bool, bool, bool|null, bool, bool, string|null, Assertions, ?Type, array<string, Type>, array<(string|int), VarTag>, bool, array<string, bool>}
60046004
*/
60056005
public function getPhpDocs(Scope $scope, Node\FunctionLike|Node\Stmt\Property $node): array
60066006
{
@@ -6030,6 +6030,7 @@ public function getPhpDocs(Scope $scope, Node\FunctionLike|Node\Stmt\Property $n
60306030
$resolvedPhpDoc = null;
60316031
$functionName = null;
60326032
$phpDocParameterOutTypes = [];
6033+
$phpDocPureUnlessCallableIsImpureParameters = [];
60336034

60346035
if ($node instanceof Node\Stmt\ClassMethod) {
60356036
if (!$scope->isInClass()) {
@@ -6152,9 +6153,10 @@ public function getPhpDocs(Scope $scope, Node\FunctionLike|Node\Stmt\Property $n
61526153
$asserts = Assertions::createFromResolvedPhpDocBlock($resolvedPhpDoc);
61536154
$selfOutType = $resolvedPhpDoc->getSelfOutTag() !== null ? $resolvedPhpDoc->getSelfOutTag()->getType() : null;
61546155
$varTags = $resolvedPhpDoc->getVarTags();
6156+
$phpDocPureUnlessCallableIsImpureParameters = $resolvedPhpDoc->getParamsPureUnlessCallableIsImpure();
61556157
}
61566158

6157-
return [$templateTypeMap, $phpDocParameterTypes, $phpDocImmediatelyInvokedCallableParameters, $phpDocClosureThisTypeParameters, $phpDocReturnType, $phpDocThrowType, $deprecatedDescription, $isDeprecated, $isInternal, $isFinal, $isPure, $acceptsNamedArguments, $isReadOnly, $docComment, $asserts, $selfOutType, $phpDocParameterOutTypes, $varTags, $isAllowedPrivateMutation];
6159+
return [$templateTypeMap, $phpDocParameterTypes, $phpDocImmediatelyInvokedCallableParameters, $phpDocClosureThisTypeParameters, $phpDocReturnType, $phpDocThrowType, $deprecatedDescription, $isDeprecated, $isInternal, $isFinal, $isPure, $acceptsNamedArguments, $isReadOnly, $docComment, $asserts, $selfOutType, $phpDocParameterOutTypes, $varTags, $isAllowedPrivateMutation, $phpDocPureUnlessCallableIsImpureParameters];
61586160
}
61596161

61606162
private function transformStaticType(ClassReflection $declaringClass, Type $type): Type

src/Reflection/Php/PhpClassReflectionExtension.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -982,7 +982,7 @@ private function inferAndCachePropertyTypes(
982982
$classScope = $classScope->enterNamespace($namespace);
983983
}
984984
$classScope = $classScope->enterClass($declaringClass);
985-
[$templateTypeMap, $phpDocParameterTypes, $phpDocImmediatelyInvokedCallableParameters, $phpDocClosureThisTypeParameters, $phpDocReturnType, $phpDocThrowType, $deprecatedDescription, $isDeprecated, $isInternal, $isFinal, $isPure, $acceptsNamedArguments, , $phpDocComment, $asserts, $selfOutType, $phpDocParameterOutTypes] = $this->nodeScopeResolver->getPhpDocs($classScope, $methodNode);
985+
[$templateTypeMap, $phpDocParameterTypes, $phpDocImmediatelyInvokedCallableParameters, $phpDocClosureThisTypeParameters, $phpDocReturnType, $phpDocThrowType, $deprecatedDescription, $isDeprecated, $isInternal, $isFinal, $isPure, $acceptsNamedArguments, , $phpDocComment, $asserts, $selfOutType, $phpDocParameterOutTypes, $varTags, $isAllowedPrivateMutation, $phpDocPureUnlessCallableIsImpureParameters] = $this->nodeScopeResolver->getPhpDocs($classScope, $methodNode);
986986
$methodScope = $classScope->enterClassMethod(
987987
$methodNode,
988988
$templateTypeMap,
@@ -1001,6 +1001,7 @@ private function inferAndCachePropertyTypes(
10011001
$phpDocParameterOutTypes,
10021002
$phpDocImmediatelyInvokedCallableParameters,
10031003
$phpDocClosureThisTypeParameters,
1004+
$phpDocPureUnlessCallableIsImpureParameters,
10041005
);
10051006

10061007
$propertyTypes = [];

src/Reflection/Php/PhpFunctionFromParserNodeReflection.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class PhpFunctionFromParserNodeReflection implements FunctionReflection, Extende
4444
* @param Type[] $parameterOutTypes
4545
* @param array<string, bool> $immediatelyInvokedCallableParameters
4646
* @param array<string, Type> $phpDocClosureThisTypeParameters
47+
* @param array<string, bool> $pureUnlessCallableIsImpureParameters
4748
*/
4849
public function __construct(
4950
FunctionLike $functionLike,
@@ -65,6 +66,7 @@ public function __construct(
6566
private array $parameterOutTypes,
6667
private array $immediatelyInvokedCallableParameters,
6768
private array $phpDocClosureThisTypeParameters,
69+
private array $pureUnlessCallableIsImpureParameters,
6870
)
6971
{
7072
$this->functionLike = $functionLike;

src/Reflection/Php/PhpMethodFromParserNodeReflection.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public function __construct(
5959
array $parameterOutTypes,
6060
array $immediatelyInvokedCallableParameters,
6161
array $phpDocClosureThisTypeParameters,
62+
array $pureUnlessCallableIsImpureParameters,
6263
)
6364
{
6465
$name = strtolower($classMethod->name->name);
@@ -114,6 +115,7 @@ public function __construct(
114115
$parameterOutTypes,
115116
$immediatelyInvokedCallableParameters,
116117
$phpDocClosureThisTypeParameters,
118+
$pureUnlessCallableIsImpureParameters,
117119
);
118120
}
119121

0 commit comments

Comments
 (0)