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 |
||
| 12 | class DockerComposeProjectManager implements ProjectManager, ProjectBuildManager |
||
| 13 | { |
||
| 14 | /** |
||
| 15 | * @var InteractiveProcessBuilder |
||
| 16 | */ |
||
| 17 | private $interactiveProcessBuilder; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * @var UserInteraction |
||
| 21 | */ |
||
| 22 | private $userInteraction; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @var ProcessRunner |
||
| 26 | */ |
||
| 27 | private $processRunner; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @var ComposeExecutableFinder |
||
| 31 | */ |
||
| 32 | private $composeExecutableFinder; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @param InteractiveProcessBuilder $interactiveProcessBuilder |
||
| 36 | * @param UserInteraction $userInteraction |
||
| 37 | * @param ProcessRunner $processRunner |
||
| 38 | * @param ComposeExecutableFinder $composeExecutableFinder |
||
| 39 | */ |
||
| 40 | public function __construct(InteractiveProcessBuilder $interactiveProcessBuilder, UserInteraction $userInteraction, ProcessRunner $processRunner, ComposeExecutableFinder $composeExecutableFinder) |
||
| 47 | |||
| 48 | /** |
||
| 49 | * {@inheritdoc} |
||
| 50 | */ |
||
| 51 | public function start(Project $project) |
||
| 68 | |||
| 69 | /** |
||
| 70 | * {@inheritdoc} |
||
| 71 | */ |
||
| 72 | public function stop(Project $project) |
||
| 78 | |||
| 79 | /** |
||
| 80 | * {@inheritdoc} |
||
| 81 | */ |
||
| 82 | public function reset(Project $project, array $containers = []) |
||
| 94 | |||
| 95 | /** |
||
| 96 | * {@inheritdoc} |
||
| 97 | */ |
||
| 98 | public function build(Project $project, array $containers = []) |
||
| 112 | } |
||
| 113 |
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.