Skip to content

Commit a27956a

Browse files
committed
Add isPureUnlessCallableIsImpureParameter method
1 parent 52fd1e8 commit a27956a

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
@@ -4600,6 +4600,23 @@ private function processArgs(
46004600
}
46014601
$parameter = $lastParameter;
46024602
}
4603+
4604+
if ($parameter instanceof ExtendedParameterReflection
4605+
&& $parameter->isPureUnlessCallableIsImpureParameter()
4606+
&& $parameterType->isTrue()->yes()
4607+
) {
4608+
if (count($parameterType->getCallableParametersAcceptors($scope)) > 0) {
4609+
$parameterCallable = $parameterType->getCallableParametersAcceptors($scope)[0];
4610+
$certain = $parameterCallable->isPure()->yes();
4611+
if ($certain) {
4612+
$impurePoints[] = new SimpleImpurePoint(
4613+
'functionCall',
4614+
sprintf('call to function %s()', $calleeReflection->getName()),
4615+
$certain,
4616+
);
4617+
}
4618+
}
4619+
}
46034620
}
46044621

46054622
$lookForUnset = false;

src/Reflection/Annotations/AnnotationsMethodParameterReflection.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,9 @@ public function getDefaultValue(): ?Type
7070
return $this->defaultValue;
7171
}
7272

73+
public function isPureUnlessCallableIsImpureParameter(): bool
74+
{
75+
return false;
76+
}
77+
7378
}

src/Reflection/ExtendedParameterReflection.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,6 @@ public function isImmediatelyInvokedCallable(): TrinaryLogic;
1919

2020
public function getClosureThisType(): ?Type;
2121

22+
public function isPureUnlessCallableIsImpureParameter(): bool;
23+
2224
}

src/Reflection/Native/ExtendedNativeParameterReflection.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public function __construct(
2222
private ?Type $outType,
2323
private TrinaryLogic $immediatelyInvokedCallable,
2424
private ?Type $closureThisType,
25+
private bool $pureUnlessCallableIsImpureParameter = false,
2526
)
2627
{
2728
}
@@ -81,4 +82,9 @@ public function getClosureThisType(): ?Type
8182
return $this->closureThisType;
8283
}
8384

85+
public function isPureUnlessCallableIsImpureParameter(): bool
86+
{
87+
return $this->pureUnlessCallableIsImpureParameter;
88+
}
89+
8490
}

src/Reflection/Php/ExtendedDummyParameter.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public function __construct(
2222
private ?Type $outType,
2323
private TrinaryLogic $immediatelyInvokedCallable,
2424
private ?Type $closureThisType,
25+
private bool $pureUnlessCallableIsImpureParameter = false,
2526
)
2627
{
2728
parent::__construct($name, $type, $optional, $passedByReference, $variadic, $defaultValue);
@@ -52,4 +53,9 @@ public function getClosureThisType(): ?Type
5253
return $this->closureThisType;
5354
}
5455

56+
public function isPureUnlessCallableIsImpureParameter(): bool
57+
{
58+
return $this->pureUnlessCallableIsImpureParameter;
59+
}
60+
5561
}

src/Reflection/Php/PhpFunctionFromParserNodeReflection.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,12 @@ public function getParameters(): array
164164
$closureThisType = null;
165165
}
166166

167+
if (isset($this->pureUnlessCallableIsImpureParameters[$parameter->var->name])) {
168+
$pureUnlessCallableIsImpureParameter = $this->pureUnlessCallableIsImpureParameters[$parameter->var->name];
169+
} else {
170+
$pureUnlessCallableIsImpureParameter = false;
171+
}
172+
167173
$parameters[] = new PhpParameterFromParserNodeReflection(
168174
$parameter->var->name,
169175
$isOptional,
@@ -177,6 +183,7 @@ public function getParameters(): array
177183
$this->parameterOutTypes[$parameter->var->name] ?? null,
178184
$immediatelyInvokedCallable,
179185
$closureThisType,
186+
$pureUnlessCallableIsImpureParameter,
180187
);
181188
}
182189

src/Reflection/Php/PhpParameterFromParserNodeReflection.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public function __construct(
2626
private ?Type $outType,
2727
private TrinaryLogic $immediatelyInvokedCallable,
2828
private ?Type $closureThisType,
29+
private bool $pureUnlessCallableIsImpureParameter,
2930
)
3031
{
3132
}
@@ -98,4 +99,9 @@ public function getClosureThisType(): ?Type
9899
return $this->closureThisType;
99100
}
100101

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

src/Reflection/Php/PhpParameterReflection.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public function __construct(
2929
private ?Type $outType,
3030
private TrinaryLogic $immediatelyInvokedCallable,
3131
private ?Type $closureThisType,
32+
private bool $pureUnlessCallableIsImpureParameter = false,
3233
)
3334
{
3435
}
@@ -133,4 +134,9 @@ public function getClosureThisType(): ?Type
133134
return $this->closureThisType;
134135
}
135136

137+
public function isPureUnlessCallableIsImpureParameter(): bool
138+
{
139+
return $this->pureUnlessCallableIsImpureParameter;
140+
}
141+
136142
}

0 commit comments

Comments
 (0)