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 |
||
| 23 | class Java extends CSharp // evil |
||
| 24 | { |
||
| 25 | public function setupRules() |
||
| 26 | { |
||
| 27 | parent::setupRules(); |
||
| 28 | |||
| 29 | $this->rules->rule('keyword')->setMatcher(new WordMatcher([ |
||
| 30 | 'abstract', 'continue', 'for', 'new', 'switch', 'assert', 'default', 'goto', 'package', 'synchronized', |
||
| 31 | 'do', 'if', 'private', 'this', 'break', 'double', 'implements', 'protected', 'throw', 'else', 'import', |
||
| 32 | 'public', 'throws', 'case', 'enum', 'instanceof', 'return', 'transient', 'catch', 'extends', 'try', 'final', |
||
| 33 | 'interface', 'static', 'class', 'finally', 'strictfp', 'volatile', 'const', 'native', 'super', 'while' |
||
| 34 | ])); |
||
| 35 | |||
| 36 | $this->rules->rule('symbol.annotation')->setMatcher(new RegexMatcher('/(@[\w\.]+)\s*(?:(?P<arguments>\((?>[^()]+|(?&arguments))*\))?)/si', [ |
||
| 37 | 1 => Token::NAME |
||
| 38 | ])); |
||
| 39 | } |
||
| 40 | |||
| 41 | public function getIdentifier() |
||
| 45 | |||
| 46 | View Code Duplication | public static function getMetadata() |
|
| 54 | } |
||
| 55 |