Skip to content

Commit e33a560

Browse files
committed
Result cache - react to property being virtual changing
1 parent 0ad2a6a commit e33a560

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

src/Dependency/ExportedNode/ExportedPropertiesNode.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public function __construct(
3030
private bool $publicSet,
3131
private bool $protectedSet,
3232
private bool $privateSet,
33+
private bool $virtual,
3334
private array $attributes,
3435
private array $hooks,
3536
)
@@ -93,7 +94,8 @@ public function equals(ExportedNode $node): bool
9394
&& $this->final === $node->final
9495
&& $this->publicSet === $node->publicSet
9596
&& $this->protectedSet === $node->protectedSet
96-
&& $this->privateSet === $node->privateSet;
97+
&& $this->privateSet === $node->privateSet
98+
&& $this->virtual === $node->virtual;
9799
}
98100

99101
/**
@@ -114,6 +116,7 @@ public static function __set_state(array $properties): self
114116
$properties['publicSet'],
115117
$properties['protectedSet'],
116118
$properties['privateSet'],
119+
$properties['virtual'],
117120
$properties['attributes'],
118121
$properties['hooks'],
119122
);
@@ -137,6 +140,7 @@ public static function decode(array $data): self
137140
$data['publicSet'],
138141
$data['protectedSet'],
139142
$data['privateSet'],
143+
$data['virtual'],
140144
array_map(static function (array $attributeData): ExportedAttributeNode {
141145
if ($attributeData['type'] !== ExportedAttributeNode::class) {
142146
throw new ShouldNotHappenException();
@@ -173,6 +177,7 @@ public function jsonSerialize()
173177
'publicSet' => $this->publicSet,
174178
'protectedSet' => $this->protectedSet,
175179
'privateSet' => $this->privateSet,
180+
'virtual' => $this->virtual,
176181
'attributes' => $this->attributes,
177182
'hooks' => $this->hooks,
178183
],

src/Dependency/ExportedNodeResolver.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use PHPStan\Dependency\ExportedNode\ExportedTraitUseAdaptation;
2626
use PHPStan\Node\Printer\ExprPrinter;
2727
use PHPStan\Node\Printer\NodeTypePrinter;
28+
use PHPStan\Reflection\ReflectionProvider;
2829
use PHPStan\ShouldNotHappenException;
2930
use PHPStan\Type\FileTypeMapper;
3031
use function array_map;
@@ -34,7 +35,11 @@
3435
final class ExportedNodeResolver
3536
{
3637

37-
public function __construct(private FileTypeMapper $fileTypeMapper, private ExprPrinter $exprPrinter)
38+
public function __construct(
39+
private ReflectionProvider $reflectionProvider,
40+
private FileTypeMapper $fileTypeMapper,
41+
private ExprPrinter $exprPrinter,
42+
)
3843
{
3944
}
4045

@@ -296,8 +301,17 @@ private function exportClassStatement(Node\Stmt $node, string $fileName, string
296301

297302
$docComment = $node->getDocComment();
298303

304+
$names = array_map(static fn (Node\PropertyItem $prop): string => $prop->name->toString(), $node->props);
305+
$virtual = false;
306+
if ($this->reflectionProvider->hasClass($namespacedName)) {
307+
$classReflection = $this->reflectionProvider->getClass($namespacedName);
308+
if ($classReflection->hasNativeProperty($names[0])) {
309+
$virtual = $classReflection->getNativeProperty($names[0])->isVirtual()->yes();
310+
}
311+
}
312+
299313
return new ExportedPropertiesNode(
300-
array_map(static fn (Node\PropertyItem $prop): string => $prop->name->toString(), $node->props),
314+
$names,
301315
$this->exportPhpDocNode(
302316
$fileName,
303317
$namespacedName,
@@ -314,6 +328,7 @@ private function exportClassStatement(Node\Stmt $node, string $fileName, string
314328
$node->isPublicSet(),
315329
$node->isProtectedSet(),
316330
$node->isPrivateSet(),
331+
$virtual,
317332
$this->exportAttributeNodes($node->attrGroups),
318333
$this->exportPropertyHooks($node->hooks, $fileName, $namespacedName),
319334
);

tests/PHPStan/Analyser/AnalyserTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,7 @@ private function createAnalyser(): Analyser
747747
self::getContainer(),
748748
new IgnoreLexer(),
749749
),
750-
new DependencyResolver($fileHelper, $reflectionProvider, new ExportedNodeResolver($fileTypeMapper, new ExprPrinter(new Printer())), $fileTypeMapper),
750+
new DependencyResolver($fileHelper, $reflectionProvider, new ExportedNodeResolver($reflectionProvider, $fileTypeMapper, new ExprPrinter(new Printer())), $fileTypeMapper),
751751
new IgnoreErrorExtensionProvider(new NetteContainer(new Container([]))),
752752
new RuleErrorTransformer(),
753753
new LocalIgnoresProcessor(),

0 commit comments

Comments
 (0)