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 |
||
| 27 | View Code Duplication | class SaveAction extends AbstractMiddlewareAction |
|
|
|
|||
| 28 | { |
||
| 29 | /** @var ConfigurationInterface */ |
||
| 30 | private $configuration; |
||
| 31 | /** @var AuthInterface */ |
||
| 32 | private $authAdapter; |
||
| 33 | /** @var EnvironmentInterface */ |
||
| 34 | private $environmentManager; |
||
| 35 | /** @var ApplicationStorage */ |
||
| 36 | private $applicationStorage; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * SaveAction constructor. |
||
| 40 | * |
||
| 41 | * @param ConfigurationInterface $configuration |
||
| 42 | * @param AuthInterface $authAdapter |
||
| 43 | * @param EnvironmentInterface $environmentManager |
||
| 44 | * @parem ApplicationStorage $applicationStorage |
||
| 45 | */ |
||
| 46 | public function __construct( |
||
| 57 | |||
| 58 | /** |
||
| 59 | * Gets template map name or template file path. |
||
| 60 | * |
||
| 61 | * @return string |
||
| 62 | */ |
||
| 63 | public function getTemplateName() : string |
||
| 67 | |||
| 68 | /** |
||
| 69 | * Gets template data. |
||
| 70 | * |
||
| 71 | * @return array |
||
| 72 | */ |
||
| 73 | public function getTemplateData() : array |
||
| 90 | } |
||
| 91 |
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.