Skip to content

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

Open

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.

Activity

  1. mergeable commented on Nov 22, 2022

    @mergeable

    This bug report is missing a link to reproduction at phpstan.org/try.

    It will most likely be closed after manual review.

  2. changed the title [-]AnonymouseClass name generated by ClassReflection->getName not transferable to Rule<CollectedDataNode> when collected by main process[/-] [+]AnonymouseClass name generated by ClassReflection->getName not transferable to Rule<CollectedDataNode> when used by main process[/+] on Nov 22, 2022
  3. changed the title [-]AnonymouseClass name generated by ClassReflection->getName not transferable to Rule<CollectedDataNode> when used by main process[/-] [+]AnonymouseClass name generated by ClassReflection->getName not transferable to Rule<CollectedDataNode> when used by different process[/+] on Nov 22, 2022
  4. changed the title [-]AnonymouseClass name generated by ClassReflection->getName not transferable to Rule<CollectedDataNode> when used by different process[/-] [+]AnonymousClass name generated by ClassReflection->getName not transferable to Rule<CollectedDataNode> when used by different process[/+] on Nov 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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