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

Private method wrongly marked as "unused" when called from sibling #252

Open
kingcrunch opened this issue Jan 27, 2015 · 3 comments · May be fixed by #1069
Open

Private method wrongly marked as "unused" when called from sibling #252

kingcrunch opened this issue Jan 27, 2015 · 3 comments · May be fixed by #1069

Comments

@kingcrunch
Copy link

<?php
class Foo
{
    public static function staticMethod($bar)
    {
        $x = new self;

        return $x->privateMethod($bar);
    }

    private function privateMethod($bar)
    {
        return $bar;
    }
}

$a = new Foo;
echo $a->staticMethod('Hello world');

See http://3v4l.org/G9sVq

phpmd markes the method privateMethod() as "unused".

@yoosefi
Copy link

yoosefi commented Apr 17, 2015

Try tagging the static method with @uses self::privateMethod()

@ravage84 ravage84 modified the milestone: 2.3.3 Nov 7, 2015
@ravage84 ravage84 modified the milestones: 2.3.3, 2.4.2 Mar 8, 2016
@manuelpichler manuelpichler modified the milestones: 2.4.2, 2.4.3 Mar 10, 2016
@manuelpichler
Copy link
Contributor

I would expect this may work in a far far away future, because we don't have data flow analysis implemented.

@chriscalip
Copy link

Error sighted; on my case Avoid unused private fields such as but class has traits with methods that makes used of said fields.

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

Successfully merging a pull request may close this issue.

6 participants