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

ASTNode expected, ASTAnonymousClass given #250

Closed
fracasula opened this issue Mar 29, 2016 · 15 comments · Fixed by #275
Closed

ASTNode expected, ASTAnonymousClass given #250

fracasula opened this issue Mar 29, 2016 · 15 comments · Fixed by #275

Comments

@fracasula
Copy link

Hi there,

I just ran phpmd on my project with this command:

vendor/bin/phpmd ./ text cleancode,codesize,controversial,design,naming,unusedcode --exclude=vendor/*,Tests/app/cache/*,Tests/app/logs/*,Tests/app/AppKernel.php

Error below:

PHP Catchable fatal error: Argument 1 passed to PDepend\Source\AST\AbstractASTNode::addChild() must implement interface PDepend\Source\AST\ASTNode, instance of PDepend\Source\AST\ASTAnonymousClass given, called in /squawka/squawka-database/vendor/pdepend/pdepend/src/main/php/PDepend/Source/Language/PHP/PHPParserVersion70.php on line 214 and defined in /squawka/squawka-database/vendor/pdepend/pdepend/src/main/php/PDepend/Source/AST/AbstractASTNode.php on line 367

Versions used:

  • "phpmd/phpmd": "2.4.2"
  • "pdepend/pdepend": "2.2.4"

There's anything I could do to find out how to solve this?

@aschwin
Copy link

aschwin commented Apr 1, 2016

+1 Same issue here. Exact same versions.

@edro
Copy link

edro commented Apr 7, 2016

+1 the same

1 similar comment
@bezrukovp
Copy link

+1 the same

@llato
Copy link

llato commented Apr 18, 2016

Maybe it can help. This error occurred when anonymous class is used:

new class()

@fracasula
Copy link
Author

Is this what you mean @llato ?

$article = (new Entity\Article())
    ->setTitle($title)
    ->setAuthor($author);
    ->setCreatedAt(new \DateTime());

All setters in my case return $this so it works like a charm 👍

@dmaij
Copy link

dmaij commented Jun 1, 2016

I changed the parent class of PHPParserGeneric from PHPParserVersion70 to PHPParserVersion56 in the pdepend source (./pdepend/pdepend/src/main/php/PDepend/Source/Language/PHP/PHPParserGeneric.php line 61).

Since I am running php56, i figures this was a weird contruction and it appears to work (for me at least)

@ChrisWesterfield
Copy link

Is there already an solution in site/in Master?

@sfeni
Copy link

sfeni commented Jun 10, 2016

same here
downgraded pdepend/pdepend to version 2.2.2 worked for me

@ChrisWesterfield
Copy link

that helped thanks 👍

@SimonFolger
Copy link

dmaij´s solution worked for me aswell, thanks

@neemzy
Copy link

neemzy commented Aug 18, 2016

So one month later, are we still better off editing vendor code to work around this? :)

@ghost
Copy link

ghost commented Sep 28, 2016

Neither downgrading to 2.2.2 (Cannot create nodes when, interval is in frozen state error) or setting the parser to PHP 5.6 is working for me. I run PHP 7.0.8.
Is there any other fix or workaround for this? Keeps me from getting green builds in jenkins as it cannot generate a JDepend xml report.

@mjacobus
Copy link

+1. Same as @fjarlaegur

@ghost
Copy link

ghost commented Sep 30, 2016

Seems like @manuelpichler is working on a fix on a closely same named branch. Last commit 14 days ago. Maybe he can give us some insight in fixing things?

EDIT: I fixed my errors. I was running Pdepend on all folders in my project. I was using this for a laravel project, as i changed all modules to just scan the /app folder, my build finally turned green.

@g4z
Copy link

g4z commented Oct 22, 2016

Thanks @fjarlaegur. I was having the same problem until I read your comment and realised I had forgotten to use --exclude vendor.

giorgiosironi added a commit to elifesciences/proofreader-php that referenced this issue Nov 2, 2016
pdepend/pdepend#250 in newer versions prevents us from using anonymous classes
@ravage84 ravage84 added this to the 2.x (unspecific) milestone May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.