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

Undefined property: PhpParser\Node\Stmt\Class_::$namespacedName #6795

Closed
canvural opened this issue Nov 9, 2021 · 1 comment
Closed

Undefined property: PhpParser\Node\Stmt\Class_::$namespacedName #6795

canvural opened this issue Nov 9, 2021 · 1 comment
Labels

Comments

@canvural
Copy link

canvural commented Nov 9, 2021

Bug Report

Subject Details
Rector version 0.12

I had this issue when I upgraded to 0.12. Unfortunately I couldn't reproduce this in playground. But I did debugging hope this is enough to get this fixed.

Full stack trace for the error

Warning: Undefined property: PhpParser\Node\Stmt\Class_::$namespacedName in /var/www/html/vendor/rector/rector/packages/NodeTypeResolver/PHPStan/CollisionGuard/MixinGuard.php on line 40
Fatal error: Uncaught Error: Call to a member function toString() on null in /var/www/html/vendor/rector/rector/packages/NodeTypeResolver/PHPStan/CollisionGuard/MixinGuard.php:40
Stack trace:
#0 /var/www/html/vendor/rector/rector/vendor/nikic/php-parser/lib/PhpParser/NodeVisitor/FirstFindingVisitor.php(42): Rector\NodeTypeResolver\PHPStan\CollisionGuard\MixinGuard->Rector\NodeTypeResolver\PHPStan\CollisionGuard{closure}(Object(PhpParser\Node\Stmt\Class_))
#1 /var/www/html/vendor/rector/rector/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php(113): PhpParser\NodeVisitor\FirstFindingVisitor->enterNode(Object(PhpParser\Node\Stmt\Class_))
#2 /var/www/html/vendor/rector/rector/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php(133): PhpParser\NodeTraverser->traverseNode(Object(PhpParser\Node\Expr\New_))
#3 /var/www/html/vendor/rector/rector/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php(196): PhpParser\NodeTraverser->traverseNode(Object(PhpParser\Node\Arg))
#4 /var/www/html/vendor/rector/rector/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php(105): PhpParser\NodeTraverser->traverseArray(Array)
#5 /var/www/html/vendor/rector/rector/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php(133): PhpParser\NodeTraverser->traverseNode(Object(PhpParser\Node\Expr\MethodCall))
#6 /var/www/html/vendor/rector/rector/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php(196): PhpParser\NodeTraverser->traverseNode(Object(PhpParser\Node\Stmt\Expression))
#7 /var/www/html/vendor/rector/rector/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php(105): PhpParser\NodeTraverser->traverseArray(Array)
#8 /var/www/html/vendor/rector/rector/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php(196): PhpParser\NodeTraverser->traverseNode(Object(PhpParser\Node\Stmt\Foreach_))
#9 /var/www/html/vendor/rector/rector/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php(105): PhpParser\NodeTraverser->traverseArray(Array)
#10 /var/www/html/vendor/rector/rector/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php(196): PhpParser\NodeTraverser->traverseNode(Object(PhpParser\Node\Stmt\ClassMethod))
#11 /var/www/html/vendor/rector/rector/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php(105): PhpParser\NodeTraverser->traverseArray(Array)
#12 /var/www/html/vendor/rector/rector/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php(196): PhpParser\NodeTraverser->traverseNode(Object(PhpParser\Node\Stmt\Trait_))
#13 /var/www/html/vendor/rector/rector/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php(105): PhpParser\NodeTraverser->traverseArray(Array)
#14 /var/www/html/vendor/rector/rector/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php(196): PhpParser\NodeTraverser->traverseNode(Object(PhpParser\Node\Stmt\Namespace_))
#15 /var/www/html/vendor/rector/rector/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php(85): PhpParser\NodeTraverser->traverseArray(Array)
#16 /var/www/html/vendor/rector/rector/vendor/nikic/php-parser/lib/PhpParser/NodeFinder.php(59): PhpParser\NodeTraverser->traverse(Array)
#17 /var/www/html/vendor/rector/rector/src/PhpParser/Node/BetterNodeFinder.php(223): PhpParser\NodeFinder->findFirst(Array, Object(Closure))
#18 /var/www/html/vendor/rector/rector/packages/NodeTypeResolver/PHPStan/CollisionGuard/MixinGuard.php(42): Rector\Core\PhpParser\Node\BetterNodeFinder->findFirst(Array, Object(Closure))
#19 /var/www/html/vendor/rector/rector/packages/NodeTypeResolver/PHPStan/Scope/PHPStanNodeScopeResolver.php(148): Rector\NodeTypeResolver\PHPStan\CollisionGuard\MixinGuard->containsMixinPhpDoc(Array)
#20 /var/www/html/vendor/rector/rector/packages/NodeTypeResolver/PHPStan/Scope/PHPStanNodeScopeResolver.php(140): Rector\NodeTypeResolver\PHPStan\Scope\PHPStanNodeScopeResolver->processNodesWithMixinHandling(Object(RectorPrefix20211108\Symplify\SmartFileSystem\SmartFileInfo), Array, Object(PHPStan\Analyser\MutatingScope), Object(Closure))
#21 /var/www/html/vendor/rector/rector/packages/NodeTypeResolver/NodeScopeAndMetadataDecorator.php(57): Rector\NodeTypeResolver\PHPStan\Scope\PHPStanNodeScopeResolver->processNodes(Array, Object(RectorPrefix20211108\Symplify\SmartFileSystem\SmartFileInfo))
#22 /var/www/html/vendor/rector/rector/src/PhpParser/AstResolver.php(319): Rector\NodeTypeResolver\NodeScopeAndMetadataDecorator->decorateNodesFromFile(Object(Rector\Core\ValueObject\Application\File), Array)
#23 /var/www/html/vendor/rector/rector/src/PhpParser/AstResolver.php(254): Rector\Core\PhpParser\AstResolver->parseFileNameToDecoratedNodes('/var/www/html/v...')
#24 /var/www/html/vendor/rector/rector/src/PhpParser/NodeFinder/PropertyFetchFinder.php(68): Rector\Core\PhpParser\AstResolver->parseClassReflectionTraits(Object(PHPStan\Reflection\ClassReflection))
#25 /var/www/html/vendor/rector/rector/rules/Removing/NodeManipulator/ComplexNodeRemover.php(68): Rector\Core\PhpParser\NodeFinder\PropertyFetchFinder->findPrivatePropertyFetches(Object(PhpParser\Node\Stmt\Property))
#26 /var/www/html/vendor/rector/rector/rules/DeadCode/Rector/Property/RemoveUnusedPrivatePropertyRector.php(65): Rector\Removing\NodeManipulator\ComplexNodeRemover->removePropertyAndUsages(Object(PhpParser\Node\Stmt\Property))
#27 /var/www/html/vendor/rector/rector/src/Rector/AbstractRector.php(249): Rector\DeadCode\Rector\Property\RemoveUnusedPrivatePropertyRector->refactor(Object(PhpParser\Node\Stmt\Property))
#28 /var/www/html/vendor/rector/rector/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php(176): Rector\Core\Rector\AbstractRector->enterNode(Object(PhpParser\Node\Stmt\Property))
#29 /var/www/html/vendor/rector/rector/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php(105): PhpParser\NodeTraverser->traverseArray(Array)
#30 /var/www/html/vendor/rector/rector/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php(196): PhpParser\NodeTraverser->traverseNode(Object(PhpParser\Node\Stmt\Class_))
#31 /var/www/html/vendor/rector/rector/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php(105): PhpParser\NodeTraverser->traverseArray(Array)
#32 /var/www/html/vendor/rector/rector/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php(196): PhpParser\NodeTraverser->traverseNode(Object(PhpParser\Node\Stmt\Namespace_))
#33 /var/www/html/vendor/rector/rector/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php(85): PhpParser\NodeTraverser->traverseArray(Array)
#34 /var/www/html/vendor/rector/rector/src/PhpParser/NodeTraverser/RectorNodeTraverser.php(52): PhpParser\NodeTraverser->traverse(Array)
#35 /var/www/html/vendor/rector/rector/src/Application/FileProcessor.php(49): Rector\Core\PhpParser\NodeTraverser\RectorNodeTraverser->traverse(Array)
#36 /var/www/html/vendor/rector/rector/src/Application/FileProcessor/PhpFileProcessor.php(132): Rector\Core\Application\FileProcessor->refactor(Object(Rector\Core\ValueObject\Application\File))
#37 /var/www/html/vendor/rector/rector/src/Application/FileProcessor/PhpFileProcessor.php(144): Rector\Core\Application\FileProcessor\PhpFileProcessor->Rector\Core\Application\FileProcessor{closure}(Object(Rector\Core\ValueObject\Application\File))
#38 /var/www/html/vendor/rector/rector/src/Application/FileProcessor/PhpFileProcessor.php(133): Rector\Core\Application\FileProcessor\PhpFileProcessor->tryCatchWrapper(Object(Rector\Core\ValueObject\Application\File), Object(Closure), Object(Rector\Core\Enum\ApplicationPhase))
#39 /var/www/html/vendor/rector/rector/src/Application/FileProcessor/PhpFileProcessor.php(91): Rector\Core\Application\FileProcessor\PhpFileProcessor->refactorNodesWithRectors(Object(Rector\Core\ValueObject\Application\File))
#40 /var/www/html/vendor/rector/rector/src/Application/ApplicationFileProcessor.php(76): Rector\Core\Application\FileProcessor\PhpFileProcessor->process(Object(Rector\Core\ValueObject\Application\File), Object(Rector\Core\ValueObject\Configuration))
#41 /var/www/html/vendor/rector/rector/src/Application/ApplicationFileProcessor.php(57): Rector\Core\Application\ApplicationFileProcessor->processFiles(Array, Object(Rector\Core\ValueObject\Configuration))
#42 /var/www/html/vendor/rector/rector/src/Console/Command/ProcessCommand.php(152): Rector\Core\Application\ApplicationFileProcessor->run(Array, Object(Rector\Core\ValueObject\Configuration))
#43 /var/www/html/vendor/rector/rector/vendor/symfony/console/Command/Command.php(274): Rector\Core\Console\Command\ProcessCommand->execute(Object(RectorPrefix20211108\Symfony\Component\Console\Input\ArgvInput), Object(RectorPrefix20211108\Symfony\Component\Console\Output\ConsoleOutput))
#44 /var/www/html/vendor/rector/rector/vendor/symfony/console/Application.php(870): RectorPrefix20211108\Symfony\Component\Console\Command\Command->run(Object(RectorPrefix20211108\Symfony\Component\Console\Input\ArgvInput), Object(RectorPrefix20211108\Symfony\Component\Console\Output\ConsoleOutput))
#45 /var/www/html/vendor/rector/rector/vendor/symfony/console/Application.php(266): RectorPrefix20211108\Symfony\Component\Console\Application->doRunCommand(Object(Rector\Core\Console\Command\ProcessCommand), Object(RectorPrefix20211108\Symfony\Component\Console\Input\ArgvInput), Object(RectorPrefix20211108\Symfony\Component\Console\Output\ConsoleOutput))
#46 /var/www/html/vendor/rector/rector/src/Console/ConsoleApplication.php(71): RectorPrefix20211108\Symfony\Component\Console\Application->doRun(Object(RectorPrefix20211108\Symfony\Component\Console\Input\ArgvInput), Object(RectorPrefix20211108\Symfony\Component\Console\Output\ConsoleOutput))
#47 /var/www/html/vendor/rector/rector/vendor/symfony/console/Application.php(162): Rector\Core\Console\ConsoleApplication->doRun(Object(RectorPrefix20211108\Symfony\Component\Console\Input\ArgvInput), Object(RectorPrefix20211108\Symfony\Component\Console\Output\ConsoleOutput))
#48 /var/www/html/vendor/rector/rector/bin/rector.php(63): RectorPrefix20211108\Symfony\Component\Console\Application->run()
#49 /var/www/html/vendor/rector/rector/bin/rector(5): require_once('/var/www/html/v...')
#50 {main}
thrown in /var/www/html/vendor/rector/rector/packages/NodeTypeResolver/PHPStan/CollisionGuard/MixinGuard.php on line 40

And in MixinGuard I put some var_dump statements. So looks like when the $node is instance of \PhpParser\Node\Stmt\Class_, namespacedName still can be not set. var_dump($node->name) produces

object(PhpParser\Node\Identifier)#173688 (2) {
  ["name"]=>
  string(46) "AnonymousClass272db9eb1a9eaf0e004a2a9df7619c98"
  ["attributes":protected]=>
  array(0) {
  }
}

and this class name looks like coming from here.

So is it possible to add a guard for this case in the method?

@canvural canvural added the bug label Nov 9, 2021
samsonasik added a commit to rectorphp/rector-src that referenced this issue Nov 9, 2021
@samsonasik
Copy link
Member

I created PR rectorphp/rector-src#1197 for it.

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

No branches or pull requests

2 participants