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 |
||
| 30 | class SetlocaleStringSniff extends AbstractFunctionCallParameterSniff |
||
| 31 | { |
||
| 32 | |||
| 33 | /** |
||
| 34 | * Functions to check for. |
||
| 35 | * |
||
| 36 | * @var array |
||
| 37 | */ |
||
| 38 | protected $targetFunctions = array( |
||
| 39 | 'setlocale' => true, |
||
| 40 | ); |
||
| 41 | |||
| 42 | |||
| 43 | /** |
||
| 44 | * Do a version check to determine if this sniff needs to run at all. |
||
| 45 | * |
||
| 46 | * @return bool |
||
| 47 | */ |
||
| 48 | protected function bowOutEarly() |
||
| 52 | |||
| 53 | |||
| 54 | /** |
||
| 55 | * Process the parameters of a matched function. |
||
| 56 | * |
||
| 57 | * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
||
| 58 | * @param int $stackPtr The position of the current token in the stack. |
||
| 59 | * @param string $functionName The token content (function name) which was matched. |
||
| 60 | * @param array $parameters Array with information about the parameters. |
||
| 61 | * |
||
| 62 | * @return int|void Integer stack pointer to skip forward or void to continue |
||
| 63 | * normal file processing. |
||
| 64 | */ |
||
| 65 | public function processParameters(\PHP_CodeSniffer_File $phpcsFile, $stackPtr, $functionName, $parameters) |
||
| 98 | }//end class |
||
| 99 |