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

Name called on "PhpParser\Node\Expr\MethodCall" is not possible #5690

Closed
Tracked by #10
DieterHolvoet opened this issue Feb 26, 2021 · 16 comments
Closed
Tracked by #10

Name called on "PhpParser\Node\Expr\MethodCall" is not possible #5690

DieterHolvoet opened this issue Feb 26, 2021 · 16 comments
Labels

Comments

@DieterHolvoet
Copy link

Bug Report

Subject Details
Rector version 0.9.31
Installed as prefixed Rector
Could not process "public/modules/custom/wmcustom/src/Entity/File.php" file, due to:
         "Name called on "PhpParser\Node\Expr\MethodCall" is not possible. Use $this->getName($node->name) instead"

I debugged a bit and the MethodCall in question is $this->get.

Minimal PHP Code Causing Issue

vendor/bin/rector process public/modules/custom/wmcustom/src/Entity/File.php
<?php

namespace Drupal\wmcustom\Entity;

class File extends \Drupal\file\Entity\File
{
    public function setMd5($md5): void
    {
        $this->get('md5')->value = $md5;
    }
}

Expected Behaviour

Don't fail

@samsonasik
Copy link
Member

could you run with --debug to get the nearest rule that has this issue:

vendor/bin/rector process public/modules/custom/wmcustom/src/Entity/File.php --debug

@DieterHolvoet
Copy link
Author

[parsing] public/modules/custom/wmcustom/src/Entity/File.php
[refactoring] public/modules/custom/wmcustom/src/Entity/File.php
    [applying] Rector\Renaming\Rector\Name\RenameClassRector
    [applying] Rector\DeadDocBlock\Rector\Node\RemoveNonExistingVarAnnotationRector
    [applying] Rector\Renaming\Rector\FileWithoutNamespace\PseudoNamespaceToNamespaceRector
    [applying] Rector\TypeDeclaration\Rector\FunctionLike\ParamTypeDeclarationRector
    [applying] Rector\TypeDeclaration\Rector\FunctionLike\ReturnTypeDeclarationRector
    [applying] Rector\DeadDocBlock\Rector\ClassMethod\RemoveUselessParamTagRector
    [applying] Rector\DeadDocBlock\Rector\ClassMethod\RemoveUselessReturnTagRector
    [applying] Rector\CodingStyle\Rector\Assign\PHPStormVarAnnotationRector
    [applying] Rector\Php74\Rector\Assign\NullCoalescingOperatorRector
    [applying] Rector\Php74\Rector\MethodCall\ChangeReflectionTypeToStringToGetNameRector
    [applying] Rector\CodingStyle\Rector\String_\SymplifyQuoteEscapeRector
    [applying] Rector\Php73\Rector\String_\SensitiveHereNowDocRector
    [applying] Rector\EarlyReturn\Rector\If_\ChangeAndIfToEarlyReturnRector
    [applying] Rector\EarlyReturn\Rector\If_\ChangeIfElseValueAssignToEarlyReturnRector
    [applying] Rector\EarlyReturn\Rector\If_\ChangeNestedIfsToEarlyReturnRector
    [applying] Rector\EarlyReturn\Rector\If_\RemoveAlwaysElseRector
    [applying] Rector\EarlyReturn\Rector\If_\ChangeOrIfReturnToEarlyReturnRector
    [applying] Rector\Php73\Rector\FuncCall\RegexDashEscapeRector
    [applying] Rector\Php74\Rector\StaticCall\ExportToReflectionFunctionRector
    [applying] Rector\CodingStyle\Rector\FuncCall\ConsistentImplodeRector
    [applying] Rector\CodingStyle\Rector\FuncCall\CallUserFuncCallToVariadicRector
    [applying] Rector\Php73\Rector\FuncCall\ArrayKeyFirstLastRector
    [applying] Rector\Php73\Rector\FuncCall\SensitiveDefineRector
    [applying] Rector\Renaming\Rector\FuncCall\RenameFunctionRector
    [applying] Rector\Php73\Rector\FuncCall\StringifyStrNeedlesRector
    [applying] Rector\Php73\Rector\FuncCall\JsonThrowOnErrorRector
    [applying] Rector\Php74\Rector\FuncCall\ArrayKeyExistsOnPropertyRector
    [applying] Rector\Php74\Rector\FuncCall\FilterVarToAddSlashesRector
    [applying] Rector\Php74\Rector\FuncCall\GetCalledClassToStaticClassRector
    [applying] Rector\Php74\Rector\FuncCall\MbStrrposEncodingArgumentPositionRector
    [applying] Rector\Php74\Rector\Function_\ReservedFnFunctionRector
    [applying] Rector\Php74\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector
PHP Fatal error:  Uncaught Rector\Core\Exception\ShouldNotHappenException: Name called on "PhpParser\Node\Expr\MethodCall" is not possible. Use $this->getName($node->name) instead in /home/vagrant/sites/vlor/vendor/rector/rector-prefixed/packages/node-name-resolver/src/NodeNameResolver.php:85
Stack trace:
#0 /home/vagrant/sites/vlor/vendor/rector/rector-prefixed/src/NodeManipulator/PropertyFetchAssignManipulator.php(66): Rector\NodeNameResolver\NodeNameResolver->isName()
#1 /home/vagrant/sites/vlor/vendor/rector/rector-prefixed/src/NodeManipulator/PropertyFetchAssignManipulator.php(37): Rector\Core\NodeManipulator\PropertyFetchAssignManipulator->isVariableAssignToThisPropertyFetch()
#2 /home/vagrant/sites/vlor/vendor/rector/rector-prefixed/vendor/symplify/astral/src/NodeTraverser/SimpleCallableNodeTraverser.php(54): Rector\Core\NodeManipulator\PropertyFetchAssignManipulator->Rector\Core\NodeManipulator\{closure}()
#3 /home/vagrant/sites/vlor/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php(123): class@anonymous->enterNo in /home/vagrant/sites/vlor/vendor/rector/rector-prefixed/packages/node-name-resolver/src/NodeNameResolver.php on line 85
Fatal error: Uncaught Rector\Core\Exception\ShouldNotHappenException: Name called on "PhpParser\Node\Expr\MethodCall" is not possible. Use $this->getName($node->name) instead in /home/vagrant/sites/vlor/vendor/rector/rector-prefixed/packages/node-name-resolver/src/NodeNameResolver.php:85
Stack trace:
#0 /home/vagrant/sites/vlor/vendor/rector/rector-prefixed/src/NodeManipulator/PropertyFetchAssignManipulator.php(66): Rector\NodeNameResolver\NodeNameResolver->isName()
#1 /home/vagrant/sites/vlor/vendor/rector/rector-prefixed/src/NodeManipulator/PropertyFetchAssignManipulator.php(37): Rector\Core\NodeManipulator\PropertyFetchAssignManipulator->isVariableAssignToThisPropertyFetch()
#2 /home/vagrant/sites/vlor/vendor/rector/rector-prefixed/vendor/symplify/astral/src/NodeTraverser/SimpleCallableNodeTraverser.php(54): Rector\Core\NodeManipulator\PropertyFetchAssignManipulator->Rector\Core\NodeManipulator\{closure}()
#3 /home/vagrant/sites/vlor/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php(123): class@anonymous->enterNo in /home/vagrant/sites/vlor/vendor/rector/rector-prefixed/packages/node-name-resolver/src/NodeNameResolver.php on line 85

@samsonasik
Copy link
Member

could you share your rector.php config as well? Thank you.

@samsonasik
Copy link
Member

I can't reproduce it, could you try rector/rector: "dev-master" ? If the issue persist, it would be better if you can provide a failing test case PR.

Thank you.

@TomasVotruba
Copy link
Member

TomasVotruba commented Feb 27, 2021

A https://getrector.org/demo link is needed to reproduce.

@Aerendir
Copy link
Contributor

Aerendir commented Mar 1, 2021

@TomasVotruba
Copy link
Member

TomasVotruba commented Mar 1, 2021

Github Action is way to complicated to analyze. Failing PR test would also do.
Without that, we can't see replicate the bug in isolated controlled space and we're unable to fix it.

@Aerendir
Copy link
Contributor

Aerendir commented Mar 1, 2021

@TomasVotruba , it is not possible for us to replicate the issue as the demo doesn't use PHPUnit.

It is not complicated, trust me.

Follow those steps:

  1. Checkout this branch: https://github.com/Aerendir/bundle-stripe/tree/dependabot/composer/dev/rector/rector-0.9.29
  2. Run composer install
  3. Run vendor/bin/rector process

You will see the error and start better understanding what's going on.

You know I can generally create a failing test case, but in this situation it is impossible for me to reproduce the bug as it only happens if the test class inherits from TestCase and this is not possible in the current implementation of the Rector's Demo.

@TomasVotruba
Copy link
Member

I don't talk about Rector demo, but failing test case fixture. It must be replicable in Rector test case here

Here is step by step tutorial how to add it: https://github.com/rectorphp/rector/blob/master/docs/how_to_add_test_for_rector_rule.md

@Bl00D4NGEL
Copy link
Contributor

Bl00D4NGEL commented Mar 10, 2021

Seems to be the same error as #5797.

PHP Fatal error:  Uncaught Rector\Core\Exception\ShouldNotHappenException: Name called on "PhpParser\Node\Expr\MethodCall" is not possible. Use $this->getName($node->name) instead in <path-to-bundle-stripe>bundle-stripe/vendor/rector/rector/packages/node-name-resolver/src/NodeNameResolver.php:104
Stack trace:
#0 <path-to-bundle-stripe>bundle-stripe/vendor/rector/rector/src/Rector/AbstractTemporaryRector.php(325): Rector\NodeNameResolver\NodeNameResolver->isName()
#1 <path-to-bundle-stripe>bundle-stripe/vendor/rector/rector/rules/phpunit/src/Rector/MethodCall/AssertTrueFalseToSpecificMethodRector.php(97): Rector\Core\Rector\AbstractTemporaryRector->isName()
#2 <path-to-bundle-stripe>bundle-stripe/vendor/rector/rector/src/Rector/AbstractTemporaryRector.php(300): Rector\PHPUnit\Rector\MethodCall\AssertTrueFalseToSpecificMethodRector->refactor()
#3 <path-to-bundle-stripe>bundle-stripe/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php(123): Rector\Core\Rector\AbstractTemporaryRector->enterNode()
#4 <path-to-bundle-stripe>bundle-stripe/vendor/nikic/php-parser/lib/PhpParser/NodeTr in <path-to-bundle-stripe>bundle-stripe/vendor/rector/rector/packages/node-name-resolver/src/NodeNameResolver.php on line 104
Fatal error: Uncaught Rector\Core\Exception\ShouldNotHappenException: Name called on "PhpParser\Node\Expr\MethodCall" is not possible. Use $this->getName($node->name) instead in <path-to-bundle-stripe>bundle-stripe/vendor/rector/rector/packages/node-name-resolver/src/NodeNameResolver.php:104
Stack trace:
#0 <path-to-bundle-stripe>bundle-stripe/vendor/rector/rector/src/Rector/AbstractTemporaryRector.php(325): Rector\NodeNameResolver\NodeNameResolver->isName()
#1 <path-to-bundle-stripe>bundle-stripe/vendor/rector/rector/rules/phpunit/src/Rector/MethodCall/AssertTrueFalseToSpecificMethodRector.php(97): Rector\Core\Rector\AbstractTemporaryRector->isName()
#2 <path-to-bundle-stripe>bundle-stripe/vendor/rector/rector/src/Rector/AbstractTemporaryRector.php(300): Rector\PHPUnit\Rector\MethodCall\AssertTrueFalseToSpecificMethodRector->refactor()
#3 <path-to-bundle-stripe>bundle-stripe/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php(123): Rector\Core\Rector\AbstractTemporaryRector->enterNode()
#4 <path-to-bundle-stripe>bundle-stripe/vendor/nikic/php-parser/lib/PhpParser/NodeTr in <path-to-bundle-stripe>bundle-stripe/vendor/rector/rector/packages/node-name-resolver/src/NodeNameResolver.php on line 104

Probably fixed with dev-master and/or next release

@samsonasik
Copy link
Member

@DieterHolvoet could you try "rector/rector": "dev-master" and verify if it is already fixed ?

@DieterHolvoet
Copy link
Author

I tried it using "rector/rector-prefixed": "dev-master#3f0bca8" and I'm still having the same issue.

@noglitchyo
Copy link

noglitchyo commented Mar 15, 2021

I was running into the same issue with version 0.9.31 for multiple files.

Here is an extract of the debug output:

[refactoring] app/Jobs/Tenant/ScheduledSurvey/SendAdminResultsEmailJob.php
    [applying] Rector\DeadCode\Rector\Stmt\RemoveUnreachableStatementRector
    [applying] Rector\DeadCode\Rector\Class_\RemoveUnusedDoctrineEntityMethodAndPropertyRector
    [applying] Rector\DeadCode\Rector\Class_\RemoveEmptyAbstractClassRector
    [applying] Rector\DeadCode\Rector\ClassMethod\RemoveEmptyClassMethodRector
    [applying] Rector\DeadCode\Rector\ClassMethod\RemoveUnusedParameterRector
    [applying] Rector\DeadCode\Rector\FunctionLike\RemoveOverriddenValuesRector
    [applying] Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPrivateMethodRector
    [applying] Rector\DeadCode\Rector\FunctionLike\RemoveCodeAfterReturnRector
    [applying] Rector\DeadCode\Rector\ClassMethod\RemoveDeadConstructorRector
    [applying] Rector\DeadCode\Rector\FunctionLike\RemoveDeadReturnRector
    [applying] Rector\DeadCode\Rector\ClassMethod\RemoveDelegatingParentCallRector
    [applying] Rector\PHPUnit\Rector\ClassMethod\RemoveEmptyTestMethodRector
    [applying] Rector\DeadCode\Rector\FunctionLike\RemoveDuplicatedIfReturnRector
    [applying] Rector\DeadCode\Rector\ClassMethod\RemoveDeadRecursiveClassMethodRector
    [applying] Rector\DeadCode\Rector\ClassMethod\RemoveUnusedConstructorParamRector
    [applying] Rector\DeadCode\Rector\If_\UnwrapFutureCompatibleIfFunctionExistsRector
    [applying] Rector\DeadCode\Rector\If_\UnwrapFutureCompatibleIfPhpVersionRector
    [applying] Rector\DeadCode\Rector\For_\RemoveDeadIfForeachForRector
    [applying] Rector\DeadCode\Rector\If_\SimplifyIfElseWithSameContentRector
    [applying] Rector\DeadCode\Rector\If_\RemoveUnusedNonEmptyArrayBeforeForeachRector
    [applying] Rector\DeadCode\Rector\If_\RemoveDeadInstanceOfRector
    [applying] Rector\DeadCode\Rector\MethodCall\RemoveDefaultArgumentValueRector
    [applying] Rector\DeadCode\Rector\Expression\RemoveDeadStmtRector
    [applying] Rector\DeadCode\Rector\Expression\SimplifyMirrorAssignRector
    [applying] Rector\DeadCode\Rector\MethodCall\RemoveEmptyMethodCallRector
    [applying] Rector\DeadCode\Rector\Assign\RemoveDoubleAssignRector
    [applying] Rector\DeadCode\Rector\Assign\RemoveUnusedVariableAssignRector
    [applying] Rector\DeadCode\Rector\Assign\RemoveAssignOfVoidReturnFunctionRector
    [applying] Rector\Naming\Rector\Property\UnderscoreToCamelCasePropertyNameRector
    [applying] Rector\DeadCode\Rector\Property\RemoveUnusedPrivatePropertyRector
    [applying] Rector\DeadCode\Rector\Property\RemoveSetterOnlyPropertyAndMethodCallRector
    [applying] Rector\DeadCode\Rector\PropertyProperty\RemoveNullPropertyInitializationRector
    [applying] Rector\DeadCode\Rector\StaticCall\RemoveParentCallWithoutParentRector
    [applying] Rector\DeadCode\Rector\Concat\RemoveConcatAutocastRector
    [applying] Rector\DeadCode\Rector\BinaryOp\RemoveDuplicatedInstanceOfRector
    [applying] Rector\CodeQuality\Rector\Return_\SimplifyUselessVariableRector
    [applying] Rector\DeadCode\Rector\Return_\RemoveDeadConditionAboveReturnRector
    [applying] Rector\RectorGenerator\Rector\Closure\AddNewServiceToSymfonyPhpConfigRector
    [applying] Rector\DeadCode\Rector\Array_\RemoveDuplicatedArrayKeyRector
PHP Fatal error:  Uncaught Rector\Core\Exception\ShouldNotHappenException: Name called on "PhpParser\Node\Expr\MethodCall" is not possible. Use $this->getName($node->name) instead in /var/www/html/vendor/rector/rector/packages/node-name-resolver/src/NodeNameResolver.php:104
Stack trace:
#0 /var/www/html/vendor/rector/rector/packages/node-name-resolver/src/NodeNameResolver.php(200): Rector\NodeNameResolver\NodeNameResolver->isName()
#1 /var/www/html/vendor/rector/rector/rules/naming/src/PropertyRenamer/PropertyFetchRenamer.php(43): Rector\NodeNameResolver\NodeNameResolver->isLocalPropertyFetchNamed()
#2 /var/www/html/vendor/symplify/astral/src/NodeTraverser/SimpleCallableNodeTraverser.php(61): Rector\Naming\PropertyRenamer\PropertyFetchRenamer->Rector\Naming\PropertyRenamer\{closure}()
#3 /var/www/html/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php(123): class@anonymous->enterNode()
#4 /var/www/html/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php(146): PhpParser\NodeTraverser->traverseNode()
#5 /var/www/html/ve in /var/www/html/vendor/rector/rector/packages/node-name-resolver/src/NodeNameResolver.php on line 104
Fatal error: Uncaught Rector\Core\Exception\ShouldNotHappenException: Name called on "PhpParser\Node\Expr\MethodCall" is not possible. Use $this->getName($node->name) instead in /var/www/html/vendor/rector/rector/packages/node-name-resolver/src/NodeNameResolver.php:104
Stack trace:
#0 /var/www/html/vendor/rector/rector/packages/node-name-resolver/src/NodeNameResolver.php(200): Rector\NodeNameResolver\NodeNameResolver->isName()
#1 /var/www/html/vendor/rector/rector/rules/naming/src/PropertyRenamer/PropertyFetchRenamer.php(43): Rector\NodeNameResolver\NodeNameResolver->isLocalPropertyFetchNamed()
#2 /var/www/html/vendor/symplify/astral/src/NodeTraverser/SimpleCallableNodeTraverser.php(61): Rector\Naming\PropertyRenamer\PropertyFetchRenamer->Rector\Naming\PropertyRenamer\{closure}()
#3 /var/www/html/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php(123): class@anonymous->enterNode()
#4 /var/www/html/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php(146): PhpParser\NodeTraverser->traverseNode()
#5 /var/www/html/ve in /var/www/html/vendor/rector/rector/packages/node-name-resolver/src/NodeNameResolver.php on line 104

and the rector.php:

return static function (ContainerConfigurator $containerConfigurator): void {
    // get parameters
    $parameters = $containerConfigurator->parameters();

    // Define what rule sets will be applied
    $parameters->set(Option::SETS, [
        SetList::DEAD_CODE,
    ]);

    // get services (needed for register a single rule)
     $services = $containerConfigurator->services();

    // register a single rule
     $services->set(UnderscoreToCamelCasePropertyNameRector::class);
};

However, I tried with "rector/rector": "dev-master" as asked by @samsonasik and I could not reproduce the errors anymore for all files where it was failing.

@samsonasik
Copy link
Member

latest is currently dev-main

@TomasVotruba
Copy link
Member

@Aerendir Thank you for the repository 👍 , I'm just trying new Rector there

Ref: #5690 (comment)

I've tried it apart few removed sets the Rector passes well ✔️

Peek 2021-03-15 23-34

@Aerendir
Copy link
Contributor

Glad to be helpful and many thank you for the fix! ❤️

TomasVotruba added a commit that referenced this issue Mar 5, 2024
rectorphp/rector-src@104f656 [Performance] [TypeDeclaration] No need check parent method when method is private on AddVoidReturnTypeWhereNoReturnRector (#5690)
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

6 participants