0

I have two class :

class EntityVoter
{
    protected function canPutToBlockChain($entity, $viewer)
    {
        return false;
    }
}
class VerificationVoter extends EntityVoter
{
    public function canPutToBlockChain($entity, $viewer)
    {
        return $this->canShare($entity, $viewer);
    }
}

PHPMD scan EntityVoter class and throw: Avoid unused parameters such as '$entity', '$viewer'.

My solution is creating a interface:

interface EntityVoterInterface 
{
     function canPutToBlockChain($entity, $viewer);
}

and then add @inhericDoc annotation:

class EntityVoter implements EntityVoterInterface
{
    /**
     * @inheritDoc
     */
    protected function canPutToBlockChain($entity, $viewer)
    {
        return false;
    }
}

Is there any better solution ?

  • Just pure curiosity, what are those voter class ? are you not using `use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;` – Dylan KAS Aug 03 '21 at 09:45
  • @DylanKas Yes, I have extended abstract class `Symfony\Component\Security\Core\Authorization\Voter` on `EntityVoter` class already. I just would like to focus on phpmd scanning. – Tom Explore Aug 03 '21 at 10:30

1 Answers1

0

Another option is to suppress PHPMD warning for the rule on the method:

class EntityVoter
{
    /**
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
     */
    protected function canPutToBlockChain($entity, $viewer)
    {
        return false;
    }
}

For more information, see PHPMD Suppressing Warnings @ PHP Mess Detector documentation.

I would not use wildcard exclusion such as @SuppressWarnings("unused") but targeted exclusion is OK for warnings linked to third-party code.

Biapy
  • 349
  • 3
  • 9