phpsa icon indicating copy to clipboard operation
phpsa copied to clipboard

[Bug] Trait & unused variable

Open ddmler opened this issue 9 years ago • 5 comments

Warning: Unused variable $fqcnParts in method getMetadata() in ./src/Analyzer/Pass/Statement/ConstantNaming.php [unused-variable] Warning: Unused variable $name in method getMetadata() in ./src/Analyzer/Pass/Statement/ConstantNaming.php [unused-variable] Warning: Unused variable $description in method getMetadata() in ./src/Analyzer/Pass/Statement/ConstantNaming.php [unused-variable]

for every analyzer. But all of them are used in the trait method.

ddmler avatar Oct 12 '16 13:10 ddmler

This is caused because Trait method is merged into this Class but anyway We cannot compile method in Trait because Trait's method can use another Class where it's used, recursion oops

Another moment $fqcnParts is not used because FunctionCall to end, didnt mark this argument is used, I am worry about FunctionCall, can you take a look?

ovr avatar Oct 12 '16 14:10 ovr

Unused variable happens for me in class, variable is initialized and passed as argument to method of a class, im getting noticed that it is unused but clearly it is.

Also i noticed that all warning of unused variables are when variable is passed to method as argument.

kilgaloon avatar Dec 06 '16 10:12 kilgaloon

@Kilgaloon This is caused only for static method call, I am going to fix it

ovr avatar Dec 07 '16 05:12 ovr

@Kilgaloon

Fixed in master branch in https://github.com/ovr/phpsa/commit/9bcb42c7032c7f1d191273e82015da3de8ea96d7

Tested on

class Test
{
    /**
     * @return bool
     */
    public function returnTrue()
    {
        $a = '127.0.0.1';

        self::inet_pton($a);
    }

    /**
     * @param $test
     * @return int
     */
    public static function inet_pton($test)
    {
        return inet_pton($test);
    }
}

Can you try latest changes from master branch?

Thanks

ovr avatar Dec 07 '16 05:12 ovr

I can confirm that this is working now, but another problem is happening right now. It is related with unused variables, i will create new issue about this. #280

kilgaloon avatar Dec 07 '16 13:12 kilgaloon