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 | class ValidRule extends StandardRule |
||
13 | { |
||
14 | const SCHEMA = 'schema.xsd'; |
||
15 | const NON_STRICT_SCHEMA = 'nonStrictSchema.xsd'; |
||
16 | const INDEX = 'siteindex.xsd'; |
||
17 | |||
18 | private $strictMode; |
||
19 | |||
20 | protected $contentTypes = array('text/xml', 'application/xml'); |
||
21 | |||
22 | public function init($strictMode = true) |
||
26 | |||
27 | private function getSchema($isIndex) |
||
39 | |||
40 | View Code Duplication | private function validateBody($body, $filename, $isIndex = TRUE) |
|
52 | |||
53 | /** |
||
54 | * @param string |
||
55 | * @return array |
||
56 | */ |
||
57 | private function getLocations($body) |
||
74 | |||
75 | protected function doValidation(Response $response) |
||
88 | } |
||
89 |
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.