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 | View Code Duplication | class CleanParamParser implements ParserInterface, RobotsTxtInterface |
|
|
|
|||
| 13 | { |
||
| 14 | use DirectiveParserCommons; |
||
| 15 | use UrlParser; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * Directive |
||
| 19 | */ |
||
| 20 | const DIRECTIVE = self::DIRECTIVE_CLEAN_PARAM; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * Clean-param array |
||
| 24 | * @var array |
||
| 25 | */ |
||
| 26 | private $array = []; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * CleanParam constructor. |
||
| 30 | */ |
||
| 31 | public function __construct() |
||
| 34 | |||
| 35 | /** |
||
| 36 | * Add |
||
| 37 | * |
||
| 38 | * @param string $line |
||
| 39 | * @return bool |
||
| 40 | */ |
||
| 41 | public function add($line) |
||
| 53 | |||
| 54 | /** |
||
| 55 | * Check |
||
| 56 | * |
||
| 57 | * @param string $path |
||
| 58 | * @return bool |
||
| 59 | */ |
||
| 60 | public function check($path) |
||
| 75 | |||
| 76 | /** |
||
| 77 | * Export rules |
||
| 78 | * |
||
| 79 | * @return string[][][] |
||
| 80 | */ |
||
| 81 | public function export() |
||
| 85 | |||
| 86 | /** |
||
| 87 | * Render |
||
| 88 | * |
||
| 89 | * @return string[] |
||
| 90 | */ |
||
| 91 | public function render() |
||
| 101 | } |
||
| 102 |
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.