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 |
||
8 | class UserInteractionPipe implements Pipe |
||
9 | { |
||
10 | /** |
||
11 | * @var UserInteraction |
||
12 | */ |
||
13 | private $userInteraction; |
||
14 | |||
15 | /** |
||
16 | * @param UserInteraction $userInteraction |
||
17 | */ |
||
18 | public function __construct(UserInteraction $userInteraction) |
||
22 | |||
23 | /** |
||
24 | * Rewind pipe from the beginning of the process. |
||
25 | * |
||
26 | * @param InteractiveProcess $process |
||
27 | */ |
||
28 | public function rewind(InteractiveProcess $process) |
||
29 | { |
||
30 | $process = $process->getProcess(); |
||
31 | |||
32 | $this->error($process->getErrorOutput()); |
||
33 | $this->output($process->getOutput()); |
||
34 | } |
||
35 | |||
36 | /** |
||
37 | * {@inheritdoc} |
||
38 | */ |
||
39 | public function error($buffer) |
||
43 | |||
44 | /** |
||
45 | * {@inheritdoc} |
||
46 | */ |
||
47 | public function output($buffer) |
||
51 | |||
52 | /** |
||
53 | * @param string $prefix |
||
54 | * @param array $lines |
||
55 | */ |
||
56 | private function pipeLinesWithPrefix($prefix, array $lines) |
||
65 | } |
||
66 |
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.