Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php |
||
| 20 | View Code Duplication | class InvalidService extends \InvalidArgumentException implements Exception { |
|
|
|
|||
| 21 | |||
| 22 | /** |
||
| 23 | * Create a new instance of the exception for a service class name that is |
||
| 24 | * not recognized. |
||
| 25 | * |
||
| 26 | * @since %VERSION% |
||
| 27 | * |
||
| 28 | * @param string $service Class name of the service that was not recognized. |
||
| 29 | * |
||
| 30 | * @return static |
||
| 31 | */ |
||
| 32 | public static function from_service( $service ) { |
||
| 42 | } |
||
| 43 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.