Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No node to visit provided for visitAnonymousClass #919

Open
6 tasks done
adamculp opened this issue Nov 12, 2021 · 5 comments
Open
6 tasks done

No node to visit provided for visitAnonymousClass #919

adamculp opened this issue Nov 12, 2021 · 5 comments

Comments

@adamculp
Copy link

  • PHPMD version: 2.10.2snapshot202107221018
  • PHP Version: 7.4.3
  • Installation type: (phar file)
  • Operating System / Distribution & Version: (Windows 10)

Current Behavior

When issuing the following command:

php phpmd.phar ./ng/backend xml codesize --exclude 'vendor' --reportfile 'phpmd_results.xml'

After about 20 seconds I receive the following message:

No node to visit provided for visitAnonymousClass

Also, the result file phpmd_results.xml is empty.

Expected Behavior

After some time, the phpmd_results.xml would contain the results.

Steps To Reproduce:

From within my project directory, use the following command to get phpmd:

$ wget -c https://phpmd.org/static/latest/phpmd.phar

Then issue the command above for phpmd to analyse the code.

Checks before submitting

  • Be sure that there isn't already an issue about this. See: Issues list I saw a past issue closed, from a couple versions ago. The code has significantly changed since then.
  • Be sure that there isn't already a pull request about this. See: Pull requests
  • I have added every step to reproduce the bug.
  • If possible I added relevant code examples.
  • This issue is about 1 bug and nothing more.
  • The issue has a descriptive title. For example: "JSON rendering failed on Windows for filenames with space".
@adamculp
Copy link
Author

Note: I get this same error when attempting to use PDepend, as well.

@kylekatarnls
Copy link
Member

Regarding the message, it probably fails to parse an anonymous class. Please try to spot the occurrences of new class in your command, comment/uncomment them to see which one fails.

@adamculp
Copy link
Author

adamculp commented Nov 18, 2021

@kylekatarnls I confirmed there were 2 instances of new class, and both of them resulted in the same message. (commented out one at a time to confirm)

They both fit this pattern:

class MyClass
{
    public function myFunction()
    {
        $myParameter = new class($value) extends AnotherClass {

            public function __construct($someValue)
            {
                // do something
            }

            public function doSomething()
            {
                // do something
            }
        };
    }
}

Any other info I can provide?

@kylekatarnls
Copy link
Member

Hello, when using:
$myParameter = new class... {...}
I get Unexpected token: }

I assumed the ; was missing and fixed it:
$myParameter = new class... {...};
Then it works just fine for me: phpmd_results.xml is generated with no error.

Are you able to create a 1-file project that reproduces this bug?

Thanks 🙏

@adamculp
Copy link
Author

Thanks @kylekatarnls, that was my typo. The original code does have semicolon. I've corrected above to add the semicolon. However, this next week I will re-test to see if this is still happening.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants