Rector: [PHP] StaticCallOnNonStaticToInstanceCallRector incorrect change with dynamic method name

Created on 29 Jul 2020  路  3Comments  路  Source: rectorphp/rector

Bug Report

| Subject | Details |
| :------------- | :---------------------------------------------------------------|
| Rector version | 0.8.x-dev@efa35bb |
| Installed as | composer dependency |

StaticCallOnNonStaticToInstanceCallRector incorrectly replaces static call to non static call if method name is dynamic.

Bug introduced in commit 791fe51b4a1a736380b56eefda79db62a7737bf5.

Minimal PHP Code Causing Issue

https://getrector.org/demo/cad7b22e-bf0c-4623-beb8-5e76b14b1ad7

<?php

class SomeClass
{
    public static function someMethod()
    {
        return true;
    }
}

class MyClass
{
    public function run()
    {
        $method = 'someMethod';

        SomeClass::$method();
    }
}
    ---------- begin diff ----------
--- Original
+++ New
@@ -14,6 +14,6 @@
     {
         $method = 'someMethod';

-        SomeClass::$method();
+        (new SomeClass())->{$method}();
     }
 }
    ----------- end diff -----------


Applied rules:

 * Rector\Php70\Rector\StaticCall\StaticCallOnNonStaticToInstanceCallRector

Expected Behaviour

No changes

bug

All 3 comments

Thanks for the report!

Could you send pull-request with failing fixture to StaticCallOnNonStaticToInstanceCallRectorTest?

pull request for failing test: https://github.com/rectorphp/rector/pull/3825

Just fixed, thanks for the test fixture :+1:

Was this page helpful?
0 / 5 - 0 ratings