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 |
||
9 | class PhpCsToolProcessor implements PhpCsToolProcessorInterface |
||
10 | { |
||
11 | /** |
||
12 | * @var ToolPathFinder |
||
13 | */ |
||
14 | private $toolPathFinder; |
||
15 | |||
16 | /** |
||
17 | * PhpCsToolProcessor constructor. |
||
18 | * |
||
19 | * @param ToolPathFinder $toolPathFinder |
||
20 | */ |
||
21 | public function __construct(ToolPathFinder $toolPathFinder) |
||
25 | |||
26 | /** |
||
27 | * @param string $file |
||
28 | * @param string $standard |
||
29 | * @param string $ignore |
||
30 | * |
||
31 | * @return string |
||
32 | */ |
||
33 | public function process($file, $standard, $ignore) |
||
39 | |||
40 | /** |
||
41 | * @param string $file |
||
42 | * @param string $standard |
||
43 | * @param string $ignore |
||
44 | * |
||
45 | * @return Process |
||
46 | */ |
||
47 | private function execute($file, $standard, $ignore) |
||
63 | |||
64 | /** |
||
65 | * @param Process $process |
||
66 | * |
||
67 | * @return null|string |
||
68 | * |
||
69 | * @throws \Symfony\Component\Process\Exception\LogicException |
||
70 | */ |
||
71 | View Code Duplication | private function setErrors(Process $process) |
|
79 | } |
||
80 |
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.