diff --git a/.github/workflows/e2e-tests.yml b/.github/workflows/e2e-tests.yml index 9a44de55e92..25d0dc729a2 100644 --- a/.github/workflows/e2e-tests.yml +++ b/.github/workflows/e2e-tests.yml @@ -104,6 +104,26 @@ jobs: mv src/Bar.php.orig src/Bar.php echo -n > phpstan-baseline.neon ../../bin/phpstan -vvv + - script: | + cd e2e/result-cache-9 + echo -n > phpstan-baseline.neon + ../../bin/phpstan -vvv + patch -b src/Foo.php < patch-1.patch + cat baseline-1.neon > phpstan-baseline.neon + ../../bin/phpstan -vvv + mv src/Foo.php.orig src/Foo.php + echo -n > phpstan-baseline.neon + ../../bin/phpstan -vvv + - script: | + cd e2e/result-cache-10 + echo -n > phpstan-baseline.neon + ../../bin/phpstan -vvv + patch -b src/Foo.php < patch-1.patch + cat baseline-1.neon > phpstan-baseline.neon + ../../bin/phpstan -vvv + mv src/Foo.php.orig src/Foo.php + echo -n > phpstan-baseline.neon + ../../bin/phpstan -vvv - script: | cd e2e/bug10449 ../../bin/phpstan analyze diff --git a/e2e/result-cache-10/baseline-1.neon b/e2e/result-cache-10/baseline-1.neon new file mode 100644 index 00000000000..92bead7fb96 --- /dev/null +++ b/e2e/result-cache-10/baseline-1.neon @@ -0,0 +1,6 @@ +parameters: + ignoreErrors: + - + message: "#^Access to protected property TestResultCache10\\\\Foo\\:\\:\\$x\\.$#" + count: 1 + path: src/Bar.php diff --git a/e2e/result-cache-10/patch-1.patch b/e2e/result-cache-10/patch-1.patch new file mode 100644 index 00000000000..d3872907cdc --- /dev/null +++ b/e2e/result-cache-10/patch-1.patch @@ -0,0 +1,10 @@ +--- src/Foo.php 2022-10-24 14:28:45.000000000 +0200 ++++ src/Foo.php 2022-10-24 14:30:02.000000000 +0200 +@@ -7,7 +7,7 @@ + + public function __construct( +- public string $x, ++ protected string $x, + ) + { + } diff --git a/e2e/result-cache-10/phpstan-baseline.neon b/e2e/result-cache-10/phpstan-baseline.neon new file mode 100644 index 00000000000..e69de29bb2d diff --git a/e2e/result-cache-10/phpstan.neon b/e2e/result-cache-10/phpstan.neon new file mode 100644 index 00000000000..ddbf4c2114f --- /dev/null +++ b/e2e/result-cache-10/phpstan.neon @@ -0,0 +1,7 @@ +includes: + - phpstan-baseline.neon + +parameters: + level: 8 + paths: + - src diff --git a/e2e/result-cache-10/src/Bar.php b/e2e/result-cache-10/src/Bar.php new file mode 100644 index 00000000000..18d303482b1 --- /dev/null +++ b/e2e/result-cache-10/src/Bar.php @@ -0,0 +1,13 @@ +x; + } + +} diff --git a/e2e/result-cache-10/src/Foo.php b/e2e/result-cache-10/src/Foo.php new file mode 100644 index 00000000000..28fa7d1d083 --- /dev/null +++ b/e2e/result-cache-10/src/Foo.php @@ -0,0 +1,14 @@ +, list\\ given\\.$#" + count: 1 + path: src/Bar.php diff --git a/e2e/result-cache-9/patch-1.patch b/e2e/result-cache-9/patch-1.patch new file mode 100644 index 00000000000..e449a9c220d --- /dev/null +++ b/e2e/result-cache-9/patch-1.patch @@ -0,0 +1,10 @@ +--- src/Foo.php 2022-10-24 14:28:45.000000000 +0200 ++++ src/Foo.php 2022-10-24 14:30:02.000000000 +0200 +@@ -7,7 +7,7 @@ + + public function __construct( +- /** @var list */ ++ /** @var list */ + public array $x, + ) + { diff --git a/e2e/result-cache-9/phpstan-baseline.neon b/e2e/result-cache-9/phpstan-baseline.neon new file mode 100644 index 00000000000..e69de29bb2d diff --git a/e2e/result-cache-9/phpstan.neon b/e2e/result-cache-9/phpstan.neon new file mode 100644 index 00000000000..ddbf4c2114f --- /dev/null +++ b/e2e/result-cache-9/phpstan.neon @@ -0,0 +1,7 @@ +includes: + - phpstan-baseline.neon + +parameters: + level: 8 + paths: + - src diff --git a/e2e/result-cache-9/src/Bar.php b/e2e/result-cache-9/src/Bar.php new file mode 100644 index 00000000000..5134312e6c8 --- /dev/null +++ b/e2e/result-cache-9/src/Bar.php @@ -0,0 +1,20 @@ + $strings + */ + public function acceptStrings(array $strings): void + { + } + + public function doBar(Foo $foo): void + { + $this->acceptStrings($foo->x); + } + +} diff --git a/e2e/result-cache-9/src/Foo.php b/e2e/result-cache-9/src/Foo.php new file mode 100644 index 00000000000..7fad6761238 --- /dev/null +++ b/e2e/result-cache-9/src/Foo.php @@ -0,0 +1,15 @@ + */ + public array $x, + ) + { + } + +} diff --git a/src/Dependency/ExportedNode/ExportedParameterNode.php b/src/Dependency/ExportedNode/ExportedParameterNode.php index ab00eb55380..a86b17ec06e 100644 --- a/src/Dependency/ExportedNode/ExportedParameterNode.php +++ b/src/Dependency/ExportedNode/ExportedParameterNode.php @@ -23,6 +23,8 @@ public function __construct( private bool $variadic, private bool $hasDefault, private array $attributes, + private ?ExportedPhpDocNode $phpDoc = null, + private int $flags = 0, ) { } @@ -43,11 +45,24 @@ public function equals(ExportedNode $node): bool } } + if ($this->phpDoc === null) { + if ($node->phpDoc !== null) { + return false; + } + } elseif ($node->phpDoc !== null) { + if (!$this->phpDoc->equals($node->phpDoc)) { + return false; + } + } else { + return false; + } + return $this->name === $node->name && $this->type === $node->type && $this->byRef === $node->byRef && $this->variadic === $node->variadic - && $this->hasDefault === $node->hasDefault; + && $this->hasDefault === $node->hasDefault + && $this->flags === $node->flags; } /** @@ -62,6 +77,8 @@ public static function __set_state(array $properties): self $properties['variadic'], $properties['hasDefault'], $properties['attributes'], + $properties['phpDoc'] ?? null, + $properties['flags'] ?? 0, ); } @@ -81,6 +98,8 @@ public function jsonSerialize() 'variadic' => $this->variadic, 'hasDefault' => $this->hasDefault, 'attributes' => $this->attributes, + 'phpDoc' => $this->phpDoc, + 'flags' => $this->flags, ], ]; } @@ -102,6 +121,8 @@ public static function decode(array $data): self } return ExportedAttributeNode::decode($attributeData['data']); }, $data['attributes']), + isset($data['phpDoc']) ? ExportedPhpDocNode::decode($data['phpDoc']['data']) : null, + $data['flags'] ?? 0, ); } diff --git a/src/Dependency/ExportedNodeResolver.php b/src/Dependency/ExportedNodeResolver.php index 5a6afabe705..678d6e967df 100644 --- a/src/Dependency/ExportedNodeResolver.php +++ b/src/Dependency/ExportedNodeResolver.php @@ -221,7 +221,7 @@ public function resolve(string $fileName, Node $node): ?RootExportedNode ), $node->byRef, NodeTypePrinter::printType($node->returnType), - $this->exportParameterNodes($node->params), + $this->exportParameterNodes($node->params, $fileName, null), $this->exportAttributeNodes($node->attrGroups), ); } @@ -233,7 +233,7 @@ public function resolve(string $fileName, Node $node): ?RootExportedNode * @param Node\Param[] $params * @return ExportedParameterNode[] */ - private function exportParameterNodes(array $params): array + private function exportParameterNodes(array $params, string $fileName, ?string $className): array { $nodes = []; foreach ($params as $param) { @@ -254,6 +254,7 @@ private function exportParameterNodes(array $params): array $type = new Node\NullableType($type); } } + $docComment = $param->getDocComment(); $nodes[] = new ExportedParameterNode( $param->var->name, NodeTypePrinter::printType($type), @@ -261,6 +262,13 @@ private function exportParameterNodes(array $params): array $param->variadic, $param->default !== null, $this->exportAttributeNodes($param->attrGroups), + $this->exportPhpDocNode( + $fileName, + $className, + null, + $docComment !== null ? $docComment->getText() : null, + ), + $param->flags, ); } @@ -335,7 +343,7 @@ private function exportClassStatement(Node\Stmt $node, string $fileName, string $node->isFinal(), $node->isStatic(), NodeTypePrinter::printType($node->returnType), - $this->exportParameterNodes($node->params), + $this->exportParameterNodes($node->params, $fileName, $namespacedName), $this->exportAttributeNodes($node->attrGroups), ); } @@ -482,7 +490,7 @@ private function exportPropertyHooks( $hook->body === null, $hook->isFinal(), $hook->body instanceof Expr, - $this->exportParameterNodes($hook->params), + $this->exportParameterNodes($hook->params, $fileName, $namespacedName), $this->exportAttributeNodes($hook->attrGroups), ); }