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 |
||
| 16 | class ConfigurationFactory |
||
| 17 | { |
||
| 18 | /** |
||
| 19 | * @var ApplicationConfiguration |
||
| 20 | */ |
||
| 21 | private $applicationConfiguration; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * ConfigurationFactory constructor. |
||
| 25 | * |
||
| 26 | * @param array $configuration |
||
| 27 | */ |
||
| 28 | View Code Duplication | public function __construct(array $configuration) |
|
| 37 | |||
| 38 | /** |
||
| 39 | * Create an action configuration object. |
||
| 40 | * |
||
| 41 | * @deprecated |
||
| 42 | * |
||
| 43 | * @param $actionName |
||
| 44 | * @param AdminInterface $admin |
||
| 45 | * @param array $configuration |
||
| 46 | * @return ActionConfiguration |
||
| 47 | */ |
||
| 48 | View Code Duplication | public function createActionConfiguration($actionName, AdminInterface $admin, array $configuration = []) |
|
| 57 | |||
| 58 | /** |
||
| 59 | * Create an admin configuration object. |
||
| 60 | * |
||
| 61 | * @deprecated |
||
| 62 | * |
||
| 63 | * @param array $configuration |
||
| 64 | * @return AdminConfiguration |
||
| 65 | */ |
||
| 66 | View Code Duplication | public function createAdminConfiguration(array $configuration = []) |
|
| 75 | |||
| 76 | /** |
||
| 77 | * @deprecated |
||
| 78 | * |
||
| 79 | * Return the Application configuration. |
||
| 80 | * |
||
| 81 | * @return ApplicationConfiguration |
||
| 82 | */ |
||
| 83 | public function getApplicationConfiguration() |
||
| 87 | } |
||
| 88 |
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.