1.2.133. Class Could Be Final¶
Any class that has no extension should be
final
by default.
As stated by Matthias Noback
: If a class is not marked final, it has at least one subclass
.
Prevent your classes from being subclassed by making them final
. Sometimes, classes are not meant or thought to be derivable.
<?php
class x {} // This class is extended
class y extends x {} // This class is extended
class z extends y {} // This class is not extended
final class z2 extends y {} // This class is not extended
?>
See also Negative architecture, and assumptions about code and When to declare methods final.
1.2.133.1. Suggestions¶
Make the class final
Extends the class
1.2.133.2. Specs¶
Short name |
Classes/CouldBeFinal |
Rulesets |
|
Exakat since |
1.4.3 |
PHP Version |
All |
Severity |
Minor |
Time To Fix |
Quick (30 mins) |
Precision |
Very high |
Features |
final |
Available in |