Skip to content

Commit 76c43b4

Browse files
committed
wip
1 parent 7a3a9fe commit 76c43b4

7 files changed

+50
-0
lines changed

src/Analyser/NodeScopeResolver.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4573,6 +4573,23 @@ private function processArgs(
45734573
}
45744574
$parameter = $lastParameter;
45754575
}
4576+
4577+
if ($parameter instanceof ParameterReflectionWithPhpDocs
4578+
&& $parameter->isPureUnlessCallableIsImpureParameter()
4579+
&& $parameterType->isTrue()->yes()
4580+
) {
4581+
if (count($parameterType->getCallableParametersAcceptors($scope)) > 0) {
4582+
$parameterCallable = $parameterType->getCallableParametersAcceptors($scope)[0];
4583+
$certain = $parameterCallable->isPure()->yes();
4584+
if ($certain) {
4585+
$impurePoints[] = new SimpleImpurePoint(
4586+
'functionCall',
4587+
sprintf('call to function %s()', $calleeReflection->getName()),
4588+
$certain,
4589+
);
4590+
}
4591+
}
4592+
}
45764593
}
45774594

45784595
$lookForUnset = false;

src/Reflection/Native/NativeParameterWithPhpDocsReflection.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,6 +82,11 @@ public function getClosureThisType(): ?Type
8182
return $this->closureThisType;
8283
}
8384

85+
public function isPureUnlessCallableIsImpureParameter(): bool
86+
{
87+
return $this->pureUnlessCallableIsImpureParameter;
88+
}
89+
8490
/**
8591
* @param mixed[] $properties
8692
*/

src/Reflection/ParameterReflectionWithPhpDocs.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/Php/DummyParameterWithPhpDocs.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
@@ -168,6 +168,12 @@ public function getParameters(): array
168168
$closureThisType = null;
169169
}
170170

171+
if (isset($this->pureUnlessCallableIsImpureParameters[$parameter->var->name])) {
172+
$pureUnlessCallableIsImpureParameter = $this->pureUnlessCallableIsImpureParameters[$parameter->var->name];
173+
} else {
174+
$pureUnlessCallableIsImpureParameter = false;
175+
}
176+
171177
$parameters[] = new PhpParameterFromParserNodeReflection(
172178
$parameter->var->name,
173179
$isOptional,
@@ -181,6 +187,7 @@ public function getParameters(): array
181187
$this->parameterOutTypes[$parameter->var->name] ?? null,
182188
$immediatelyInvokedCallable,
183189
$closureThisType,
190+
$pureUnlessCallableIsImpureParameter,
184191
);
185192
}
186193

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
@@ -28,6 +28,7 @@ public function __construct(
2828
private ?Type $outType,
2929
private TrinaryLogic $immediatelyInvokedCallable,
3030
private ?Type $closureThisType,
31+
private bool $pureUnlessCallableIsImpureParameter = false,
3132
)
3233
{
3334
}
@@ -132,4 +133,9 @@ public function getClosureThisType(): ?Type
132133
return $this->closureThisType;
133134
}
134135

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

0 commit comments

Comments
 (0)