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 |
||
| 31 | class CamelCaseVariableName extends AbstractRule implements MethodAware, FunctionAware |
||
| 32 | { |
||
| 33 | /** |
||
| 34 | * @var array |
||
| 35 | */ |
||
| 36 | private $exceptions = array( |
||
| 37 | '$php_errormsg', |
||
| 38 | '$http_response_header', |
||
| 39 | '$GLOBALS', |
||
| 40 | '$_SERVER', |
||
| 41 | '$_GET', |
||
| 42 | '$_POST', |
||
| 43 | '$_FILES', |
||
| 44 | '$_COOKIE', |
||
| 45 | '$_SESSION', |
||
| 46 | '$_REQUEST', |
||
| 47 | '$_ENV', |
||
| 48 | ); |
||
| 49 | |||
| 50 | /** |
||
| 51 | * This method checks if a variable is not named in camelCase |
||
| 52 | * and emits a rule violation. |
||
| 53 | * |
||
| 54 | * @param \PHPMD\AbstractNode $node |
||
| 55 | * @return void |
||
| 56 | */ |
||
| 57 | 4 | public function apply(AbstractNode $node) |
|
| 81 | |||
| 82 | /** |
||
| 83 | * Gets array of exceptions from property |
||
| 84 | * |
||
| 85 | * @return array |
||
| 86 | */ |
||
| 87 | 2 | View Code Duplication | private function getExceptionsList() |
| 96 | } |
||
| 97 |
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.