1.2.1203. Too Many Children¶
Classes that have more than 15 children. It is worth checking if they cannot be refactored in anyway.
The threshold of 15 children can be configured. There is no technical limitation of the number of children and grand-children for a class.
The analysis doesn’t work recursively : only direct generations are counted. Only children that can be found in the code are counted.
<?php
// parent class
// calling it grandparent to avoid confusion with 'parent'
class grandparent {}
class children1 extends grandparent {}
class children2 extends grandparent {}
class children3 extends grandparent {}
class children4 extends grandparent {}
class children5 extends grandparent {}
class children6 extends grandparent {}
class children7 extends grandparent {}
class children8 extends grandparent {}
class children9 extends grandparent {}
class children11 extends grandparent {}
class children12 extends grandparent {}
class children13 extends grandparent {}
class children14 extends grandparent {}
class children15 extends grandparent {}
class children16 extends grandparent {}
class children17 extends grandparent {}
class children18 extends grandparent {}
class children19 extends grandparent {}
?>
Name |
Default |
Type |
Description |
childrenClassCount |
15 |
integer |
Threshold for too many children classes for one class. |
See also Why is subclassing too much bad (and hence why should we use prototypes to do away with it)?.
1.2.1203.1. Suggestions¶
Split the original class into more specialised classes
1.2.1203.2. Specs¶
Short name |
Classes/TooManyChildren |
Rulesets |
|
Exakat since |
0.8.4 |
PHP Version |
All |
Severity |
Minor |
Time To Fix |
Slow (1 hour) |
Precision |
Very high |
Features |
class, inheritance |
Examples |
|
Available in |