Skip to content

AnonymousClass name generated by ClassReflection->getName not transferable to Rule<CollectedDataNode> when used by different process #8410

@janedbal

Description

@janedbal

Bug report

Given following collector, rule and file:

class AnonCollector implements Collector
{
    public function getNodeType(): string {
        return InClassNode::class;
    }

    public function processNode(Node $node, Scope $scope): ?array {
        return [$node->getClassReflection()->getName()];
    }
}
class AnonRule implements Rule
{
    public function __construct(private ReflectionProvider $reflectionProvider) {}

    public function getNodeType(): string {
        return CollectedDataNode::class;
    }

    public function processNode(Node $node, Scope $scope): array
    {
        $data = $node->get(AnonCollector::class);

        foreach ($data as $dataInFile) {
            foreach ($dataInFile as $fileData) {
                foreach ($fileData as $classString) {
                    $this->reflectionProvider->getClass($classString);
                }
            }
        }
        return [];
    }

}
// anon.php
$foo = new class {};

Causes following failure when executed by vendor/bin/phpstan analyse anon.php:

 ------ --------------------------------------
  Line   N/A                                                                                                                                                       
 ------ --------------------------------------
  -1     Class AnonymousClass6d87bc9b4fb4c41ce505d40f5dd1e5f5 was not found while trying to analyse it - discovering symbols is probably not configured properly.  
         💡 Learn more at https://phpstan.org/user-guide/discovering-symbols                                                                                       
 ------ --------------------------------------

Related code. Everything is working when single process used for analysis by vendor/bin/phpstan analyse --debug anon.php

Code snippet that reproduces the problem

vendor/bin/phpstan analyse anon.php

Expected output

No error.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions