Skip to content

Commit af42198

Browse files
committed
Track PHPDoc and modifier flags on ExportedParameterNode for result cache invalidation
- Add `?ExportedPhpDocNode $phpDoc` and `int $flags` fields to `ExportedParameterNode` so that changes to `@var` annotations and visibility/readonly modifiers on promoted constructor properties invalidate the result cache - Update `ExportedNodeResolver::exportParameterNodes()` to accept file name and class name context, extract parameter doc comments, and pass modifier flags - Update all three call sites (functions, class methods, property hooks) to pass the new context parameters - Add e2e test (result-cache-9) for `@var` annotation change on a promoted property - Add e2e test (result-cache-10) for visibility change on a promoted property (public → protected)
1 parent ceeb8ab commit af42198

15 files changed

Lines changed: 162 additions & 5 deletions

File tree

.github/workflows/e2e-tests.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,26 @@ jobs:
104104
mv src/Bar.php.orig src/Bar.php
105105
echo -n > phpstan-baseline.neon
106106
../../bin/phpstan -vvv
107+
- script: |
108+
cd e2e/result-cache-9
109+
echo -n > phpstan-baseline.neon
110+
../../bin/phpstan -vvv
111+
patch -b src/Foo.php < patch-1.patch
112+
cat baseline-1.neon > phpstan-baseline.neon
113+
../../bin/phpstan -vvv
114+
mv src/Foo.php.orig src/Foo.php
115+
echo -n > phpstan-baseline.neon
116+
../../bin/phpstan -vvv
117+
- script: |
118+
cd e2e/result-cache-10
119+
echo -n > phpstan-baseline.neon
120+
../../bin/phpstan -vvv
121+
patch -b src/Foo.php < patch-1.patch
122+
cat baseline-1.neon > phpstan-baseline.neon
123+
../../bin/phpstan -vvv
124+
mv src/Foo.php.orig src/Foo.php
125+
echo -n > phpstan-baseline.neon
126+
../../bin/phpstan -vvv
107127
- script: |
108128
cd e2e/bug10449
109129
../../bin/phpstan analyze
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
parameters:
2+
ignoreErrors:
3+
-
4+
message: "#^Access to protected property TestResultCache10\\\\Foo\\:\\:\\$x\\.$#"
5+
count: 1
6+
path: src/Bar.php

e2e/result-cache-10/patch-1.patch

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
--- src/Foo.php 2022-10-24 14:28:45.000000000 +0200
2+
+++ src/Foo.php 2022-10-24 14:30:02.000000000 +0200
3+
@@ -7,7 +7,7 @@
4+
5+
public function __construct(
6+
- public string $x,
7+
+ protected string $x,
8+
)
9+
{
10+
}

e2e/result-cache-10/phpstan-baseline.neon

Whitespace-only changes.

e2e/result-cache-10/phpstan.neon

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
includes:
2+
- phpstan-baseline.neon
3+
4+
parameters:
5+
level: 8
6+
paths:
7+
- src

e2e/result-cache-10/src/Bar.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace TestResultCache10;
4+
5+
class Bar
6+
{
7+
8+
public function doBar(Foo $foo): void
9+
{
10+
echo $foo->x;
11+
}
12+
13+
}

e2e/result-cache-10/src/Foo.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace TestResultCache10;
4+
5+
class Foo
6+
{
7+
8+
public function __construct(
9+
public string $x,
10+
)
11+
{
12+
}
13+
14+
}

e2e/result-cache-9/baseline-1.neon

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
parameters:
2+
ignoreErrors:
3+
-
4+
message: "#^Parameter \\#1 \\$strings of method TestResultCache9\\\\Bar\\:\\:acceptStrings\\(\\) expects list\\<string\\>, list\\<int\\> given\\.$#"
5+
count: 1
6+
path: src/Bar.php

e2e/result-cache-9/patch-1.patch

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
--- src/Foo.php 2022-10-24 14:28:45.000000000 +0200
2+
+++ src/Foo.php 2022-10-24 14:30:02.000000000 +0200
3+
@@ -7,7 +7,7 @@
4+
5+
public function __construct(
6+
- /** @var list<string> */
7+
+ /** @var list<int> */
8+
public array $x,
9+
)
10+
{

e2e/result-cache-9/phpstan-baseline.neon

Whitespace-only changes.

0 commit comments

Comments
 (0)