Skip to content

Commit 7a3a9fe

Browse files
committed
wip
1 parent fdd28b7 commit 7a3a9fe

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
@@ -2953,6 +2953,7 @@ public function enterTrait(ClassReflection $traitReflection): self
29532953
* @param Type[] $parameterOutTypes
29542954
* @param array<string, bool> $immediatelyInvokedCallableParameters
29552955
* @param array<string, Type> $phpDocClosureThisTypeParameters
2956+
* @param array<string, bool> $phpDocPureUnlessCallableIsImpureParameters
29562957
*/
29572958
public function enterClassMethod(
29582959
Node\Stmt\ClassMethod $classMethod,
@@ -2972,6 +2973,7 @@ public function enterClassMethod(
29722973
array $parameterOutTypes = [],
29732974
array $immediatelyInvokedCallableParameters = [],
29742975
array $phpDocClosureThisTypeParameters = [],
2976+
array $phpDocPureUnlessCallableIsImpureParameters = [],
29752977
): self
29762978
{
29772979
if (!$this->isInClass()) {
@@ -3002,6 +3004,7 @@ public function enterClassMethod(
30023004
array_map(fn (Type $type): Type => $this->transformStaticType(TemplateTypeHelper::toArgument($type)), $parameterOutTypes),
30033005
$immediatelyInvokedCallableParameters,
30043006
array_map(fn (Type $type): Type => $this->transformStaticType(TemplateTypeHelper::toArgument($type)), $phpDocClosureThisTypeParameters),
3007+
$phpDocPureUnlessCallableIsImpureParameters,
30053008
),
30063009
!$classMethod->isStatic(),
30073010
);
@@ -3071,6 +3074,7 @@ private function getRealParameterDefaultValues(Node\FunctionLike $functionLike):
30713074
* @param Type[] $parameterOutTypes
30723075
* @param array<string, bool> $immediatelyInvokedCallableParameters
30733076
* @param array<string, Type> $phpDocClosureThisTypeParameters
3077+
* @param array<string, bool> $pureUnlessCallableIsImpureParameters
30743078
*/
30753079
public function enterFunction(
30763080
Node\Stmt\Function_ $function,
@@ -3089,6 +3093,7 @@ public function enterFunction(
30893093
array $parameterOutTypes = [],
30903094
array $immediatelyInvokedCallableParameters = [],
30913095
array $phpDocClosureThisTypeParameters = [],
3096+
array $pureUnlessCallableIsImpureParameters = [],
30923097
): self
30933098
{
30943099
return $this->enterFunctionLike(
@@ -3113,6 +3118,7 @@ public function enterFunction(
31133118
array_map(static fn (Type $type): Type => TemplateTypeHelper::toArgument($type), $parameterOutTypes),
31143119
$immediatelyInvokedCallableParameters,
31153120
$phpDocClosureThisTypeParameters,
3121+
$pureUnlessCallableIsImpureParameters,
31163122
),
31173123
false,
31183124
);

src/Analyser/NodeScopeResolver.php

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

608608
foreach ($stmt->params as $param) {
609609
$this->processParamNode($stmt, $param, $scope, $nodeCallback);
@@ -5978,7 +5978,7 @@ private function processNodesForCalledMethod($node, string $fileName, MethodRefl
59785978
}
59795979

59805980
/**
5981-
* @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}
5981+
* @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>}
59825982
*/
59835983
public function getPhpDocs(Scope $scope, Node\FunctionLike|Node\Stmt\Property $node): array
59845984
{
@@ -6008,6 +6008,7 @@ public function getPhpDocs(Scope $scope, Node\FunctionLike|Node\Stmt\Property $n
60086008
$resolvedPhpDoc = null;
60096009
$functionName = null;
60106010
$phpDocParameterOutTypes = [];
6011+
$phpDocPureUnlessCallableIsImpureParameters = [];
60116012

60126013
if ($node instanceof Node\Stmt\ClassMethod) {
60136014
if (!$scope->isInClass()) {
@@ -6130,9 +6131,10 @@ public function getPhpDocs(Scope $scope, Node\FunctionLike|Node\Stmt\Property $n
61306131
$asserts = Assertions::createFromResolvedPhpDocBlock($resolvedPhpDoc);
61316132
$selfOutType = $resolvedPhpDoc->getSelfOutTag() !== null ? $resolvedPhpDoc->getSelfOutTag()->getType() : null;
61326133
$varTags = $resolvedPhpDoc->getVarTags();
6134+
$phpDocPureUnlessCallableIsImpureParameters = $resolvedPhpDoc->getParamsPureUnlessCallableIsImpure();
61336135
}
61346136

6135-
return [$templateTypeMap, $phpDocParameterTypes, $phpDocImmediatelyInvokedCallableParameters, $phpDocClosureThisTypeParameters, $phpDocReturnType, $phpDocThrowType, $deprecatedDescription, $isDeprecated, $isInternal, $isFinal, $isPure, $acceptsNamedArguments, $isReadOnly, $docComment, $asserts, $selfOutType, $phpDocParameterOutTypes, $varTags, $isAllowedPrivateMutation];
6137+
return [$templateTypeMap, $phpDocParameterTypes, $phpDocImmediatelyInvokedCallableParameters, $phpDocClosureThisTypeParameters, $phpDocReturnType, $phpDocThrowType, $deprecatedDescription, $isDeprecated, $isInternal, $isFinal, $isPure, $acceptsNamedArguments, $isReadOnly, $docComment, $asserts, $selfOutType, $phpDocParameterOutTypes, $varTags, $isAllowedPrivateMutation, $phpDocPureUnlessCallableIsImpureParameters];
61366138
}
61376139

61386140
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
@@ -998,7 +998,7 @@ private function inferAndCachePropertyTypes(
998998
$classScope = $classScope->enterNamespace($namespace);
999999
}
10001000
$classScope = $classScope->enterClass($declaringClass);
1001-
[$templateTypeMap, $phpDocParameterTypes, $phpDocImmediatelyInvokedCallableParameters, $phpDocClosureThisTypeParameters, $phpDocReturnType, $phpDocThrowType, $deprecatedDescription, $isDeprecated, $isInternal, $isFinal, $isPure, $acceptsNamedArguments, , $phpDocComment, $asserts, $selfOutType, $phpDocParameterOutTypes] = $this->nodeScopeResolver->getPhpDocs($classScope, $methodNode);
1001+
[$templateTypeMap, $phpDocParameterTypes, $phpDocImmediatelyInvokedCallableParameters, $phpDocClosureThisTypeParameters, $phpDocReturnType, $phpDocThrowType, $deprecatedDescription, $isDeprecated, $isInternal, $isFinal, $isPure, $acceptsNamedArguments, , $phpDocComment, $asserts, $selfOutType, $phpDocParameterOutTypes, $varTags, $isAllowedPrivateMutation, $phpDocPureUnlessCallableIsImpureParameters] = $this->nodeScopeResolver->getPhpDocs($classScope, $methodNode);
10021002
$methodScope = $classScope->enterClassMethod(
10031003
$methodNode,
10041004
$templateTypeMap,
@@ -1017,6 +1017,7 @@ private function inferAndCachePropertyTypes(
10171017
$phpDocParameterOutTypes,
10181018
$phpDocImmediatelyInvokedCallableParameters,
10191019
$phpDocClosureThisTypeParameters,
1020+
$phpDocPureUnlessCallableIsImpureParameters,
10201021
);
10211022

10221023
$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, Paramet
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,
@@ -66,6 +67,7 @@ public function __construct(
6667
private array $parameterOutTypes,
6768
private array $immediatelyInvokedCallableParameters,
6869
private array $phpDocClosureThisTypeParameters,
70+
private array $pureUnlessCallableIsImpureParameters,
6971
)
7072
{
7173
$this->functionLike = $functionLike;

src/Reflection/Php/PhpMethodFromParserNodeReflection.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public function __construct(
6060
array $parameterOutTypes,
6161
array $immediatelyInvokedCallableParameters,
6262
array $phpDocClosureThisTypeParameters,
63+
array $pureUnlessCallableIsImpureParameters,
6364
)
6465
{
6566
$name = strtolower($classMethod->name->name);
@@ -116,6 +117,7 @@ public function __construct(
116117
$parameterOutTypes,
117118
$immediatelyInvokedCallableParameters,
118119
$phpDocClosureThisTypeParameters,
120+
$pureUnlessCallableIsImpureParameters,
119121
);
120122
}
121123

0 commit comments

Comments
 (0)