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 | View Code Duplication | class PhpLoader extends AbstractLoader implements LoaderInterface |
|
|
|||
17 | { |
||
18 | /** |
||
19 | * Determine if the variable is a template literal. |
||
20 | * |
||
21 | * This method looks for any PHP tags in the given string, |
||
22 | * which a file path would most likely not have. |
||
23 | * |
||
24 | * @todo Add support for custom delimiters. |
||
25 | * @param string $ident The template being evaluated. |
||
26 | * @return boolean |
||
27 | */ |
||
28 | protected function isTemplateString(string $ident): bool |
||
32 | |||
33 | /** |
||
34 | * Convert an identifier to a file path. |
||
35 | * |
||
36 | * @param string $ident The identifier to convert. |
||
37 | * @return string |
||
38 | */ |
||
39 | protected function filenameFromIdent(string $ident): string |
||
46 | } |
||
47 |
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.