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 |
||
5 | abstract class Parser |
||
6 | { |
||
7 | /** |
||
8 | * @var ScannerTokens |
||
9 | */ |
||
10 | protected $scanner; |
||
11 | protected $lexer; |
||
12 | |||
13 | 117 | final public function __construct(Lexer $lexer) |
|
17 | |||
18 | abstract protected function getNameFor($tokenType); |
||
19 | |||
20 | 24 | final protected function getParseError($message) |
|
29 | |||
30 | 81 | final protected function expect($tokenType) |
|
41 | |||
42 | 75 | View Code Duplication | final protected function accept($tokenType) |
52 | |||
53 | 78 | View Code Duplication | final protected function is($tokenType) |
63 | } |
||
64 |
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.