PHP

PHP

Made by DeepSource

final keyword is redundant PHP-W1082

Anti-pattern
Major
Autofix

The final keyword prevents child classes from overriding methods or constants with the final prefix. Here, the class is already defined as final; therefore, prefixing the class methods or the constants with final is redundant and safely be dropped.

Bad practice

final class User
{
   // invalid: `final` keyword is redundant here
   final public function getDetails()
   {
       // implementation for the method
   }
}
final class Status
{
   // invalid: `final` keyword is redundant here
   final public const ACTIVE = 1;
}

Recommended

final class User
{
   public function getDetails()
   {
       // implementation for the method
   }
}
final class Status
{
   public const ACTIVE = 1;
}

References