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 |
||
16 | class CodeSnifferHandler extends ToolHandler |
||
17 | { |
||
18 | /** @var array */ |
||
19 | private $files; |
||
20 | /** @var string */ |
||
21 | private $neddle; |
||
22 | /** @var string */ |
||
23 | private $standard = 'PSR2'; |
||
24 | /** |
||
25 | * @var IgnoreFiles |
||
26 | */ |
||
27 | private $ignoreFiles; |
||
28 | |||
29 | /** |
||
30 | * CodeSnifferHandler constructor. |
||
31 | * |
||
32 | * @param OutputHandlerInterface $outputHandler |
||
33 | * @param IgnoreFiles $ignoreFiles |
||
34 | */ |
||
35 | public function __construct(OutputHandlerInterface $outputHandler, IgnoreFiles $ignoreFiles) |
||
40 | |||
41 | /** |
||
42 | * @param array $messages |
||
43 | * |
||
44 | * @throws InvalidCodingStandardException |
||
45 | */ |
||
46 | public function run(array $messages) |
||
74 | |||
75 | /** |
||
76 | * @param string $neddle |
||
77 | */ |
||
78 | public function setNeddle($neddle) |
||
82 | |||
83 | /** |
||
84 | * @param array $files |
||
85 | */ |
||
86 | public function setFiles($files) |
||
90 | |||
91 | /** |
||
92 | * @param array $standard |
||
93 | */ |
||
94 | public function setStandard($standard) |
||
98 | } |
||
99 |
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.