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 |
||
| 11 | class ProcessExecutor implements ConfigAwareInterface, LoggerAwareInterface, OutputAwareInterface, VerbosityThresholdInterface |
||
| 12 | { |
||
| 13 | use ExecTrait; |
||
| 14 | use TaskIO; // uses LoggerAwareTrait and ConfigAwareTrait |
||
| 15 | use ProgressIndicatorAwareTrait; |
||
| 16 | use OutputAwareTrait; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * @param \Symfony\Component\Process\Process $process |
||
| 20 | */ |
||
| 21 | public function __construct(Process $process) |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @param \League\Container\ContainerInterface $container |
||
| 28 | * @param \Symfony\Component\Process\Process $process |
||
| 29 | * |
||
| 30 | * @return static |
||
| 31 | */ |
||
| 32 | View Code Duplication | public static function create($container, $process) |
|
| 43 | |||
| 44 | /** |
||
| 45 | * {@inheritdoc} |
||
| 46 | */ |
||
| 47 | protected function getCommandDescription() |
||
| 51 | |||
| 52 | public function run() |
||
| 56 | } |
||
| 57 |
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.