Mantas
Mantas

Reputation: 4296

PHP mess detector optional parameters

I have interface X

interface X
{
    public function foo($x, $y = 0);
}

then I have class

class xx implements X
{
    public function foo($x, $y = 0)
    {
        // use $x, but not $y
    }
}

This is perfectly normal, because I do not want to use optional $y in this implementation of X. But PMD yells that $y is unused parameter.

What can I do to easily change PMD behaviour? Only solution that I found was to suppress the warning with @SuppressWarnings(unused) annotation, bet thats not what I really like.

Upvotes: 1

Views: 742

Answers (1)

Martin Trenker
Martin Trenker

Reputation: 167

You can use {@inheritdoc}, which was introduced in this commit to skip the check for implemented methods. to this day i guess this is the only solution to this problem.

Just add this as DocBlock for the implemented method

/**
 * {@inheritdoc}
 */

Upvotes: 2

Related Questions