Skip to content

Commit 3331301

Browse files
committed
Add isPureUnlessCallableIsImpureParameter method
1 parent e99305e commit 3331301

8 files changed

+55
-0
lines changed

src/Analyser/NodeScopeResolver.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5107,6 +5107,23 @@ private function processArgs(
51075107
}
51085108
$parameter = $lastParameter;
51095109
}
5110+
5111+
if ($parameter instanceof ExtendedParameterReflection
5112+
&& $parameter->isPureUnlessCallableIsImpureParameter()
5113+
&& $parameterType->isTrue()->yes()
5114+
) {
5115+
if (count($parameterType->getCallableParametersAcceptors($scope)) > 0) {
5116+
$parameterCallable = $parameterType->getCallableParametersAcceptors($scope)[0];
5117+
$certain = $parameterCallable->isPure()->yes();
5118+
if ($certain) {
5119+
$impurePoints[] = new SimpleImpurePoint(
5120+
'functionCall',
5121+
sprintf('call to function %s()', $calleeReflection->getName()),
5122+
$certain,
5123+
);
5124+
}
5125+
}
5126+
}
51105127
}
51115128

51125129
$lookForUnset = false;

src/Reflection/Annotations/AnnotationsMethodParameterReflection.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,9 @@ public function getAttributes(): array
8080
return [];
8181
}
8282

83+
public function isPureUnlessCallableIsImpureParameter(): bool
84+
{
85+
return false;
86+
}
87+
8388
}

src/Reflection/ExtendedParameterReflection.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,6 @@ public function getClosureThisType(): ?Type;
2626
*/
2727
public function getAttributes(): array;
2828

29+
public function isPureUnlessCallableIsImpureParameter(): bool;
30+
2931
}

src/Reflection/Native/ExtendedNativeParameterReflection.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public function __construct(
2828
private TrinaryLogic $immediatelyInvokedCallable,
2929
private ?Type $closureThisType,
3030
private array $attributes,
31+
private bool $pureUnlessCallableIsImpureParameter = false,
3132
)
3233
{
3334
}
@@ -97,4 +98,9 @@ public function getAttributes(): array
9798
return $this->attributes;
9899
}
99100

101+
public function isPureUnlessCallableIsImpureParameter(): bool
102+
{
103+
return $this->pureUnlessCallableIsImpureParameter;
104+
}
105+
100106
}

src/Reflection/Php/ExtendedDummyParameter.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public function __construct(
2828
private TrinaryLogic $immediatelyInvokedCallable,
2929
private ?Type $closureThisType,
3030
private array $attributes,
31+
private bool $pureUnlessCallableIsImpureParameter = false,
3132
)
3233
{
3334
parent::__construct($name, $type, $optional, $passedByReference, $variadic, $defaultValue);
@@ -68,4 +69,9 @@ public function getAttributes(): array
6869
return $this->attributes;
6970
}
7071

72+
public function isPureUnlessCallableIsImpureParameter(): bool
73+
{
74+
return $this->pureUnlessCallableIsImpureParameter;
75+
}
76+
7177
}

src/Reflection/Php/PhpFunctionFromParserNodeReflection.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,12 @@ public function getParameters(): array
170170
$closureThisType = null;
171171
}
172172

173+
if (isset($this->pureUnlessCallableIsImpureParameters[$parameter->var->name])) {
174+
$pureUnlessCallableIsImpureParameter = $this->pureUnlessCallableIsImpureParameters[$parameter->var->name];
175+
} else {
176+
$pureUnlessCallableIsImpureParameter = false;
177+
}
178+
173179
$parameters[] = new PhpParameterFromParserNodeReflection(
174180
$parameter->var->name,
175181
$isOptional,
@@ -184,6 +190,7 @@ public function getParameters(): array
184190
$immediatelyInvokedCallable,
185191
$closureThisType,
186192
$this->parameterAttributes[$parameter->var->name] ?? [],
193+
$pureUnlessCallableIsImpureParameter,
187194
);
188195
}
189196

src/Reflection/Php/PhpParameterFromParserNodeReflection.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public function __construct(
3131
private TrinaryLogic $immediatelyInvokedCallable,
3232
private ?Type $closureThisType,
3333
private array $attributes,
34+
private bool $pureUnlessCallableIsImpureParameter,
3435
)
3536
{
3637
}
@@ -113,4 +114,9 @@ public function getAttributes(): array
113114
return $this->attributes;
114115
}
115116

117+
public function isPureUnlessCallableIsImpureParameter(): bool
118+
{
119+
return $this->pureUnlessCallableIsImpureParameter;
120+
}
121+
116122
}

src/Reflection/Php/PhpParameterReflection.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public function __construct(
3434
private TrinaryLogic $immediatelyInvokedCallable,
3535
private ?Type $closureThisType,
3636
private array $attributes,
37+
private bool $pureUnlessCallableIsImpureParameter = false,
3738
)
3839
{
3940
}
@@ -143,4 +144,9 @@ public function getAttributes(): array
143144
return $this->attributes;
144145
}
145146

147+
public function isPureUnlessCallableIsImpureParameter(): bool
148+
{
149+
return $this->pureUnlessCallableIsImpureParameter;
150+
}
151+
146152
}

0 commit comments

Comments
 (0)