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 declare(strict_types=1); |
||
13 | View Code Duplication | class FixedCG extends AbstractCharacterGroup |
|
|
|||
14 | { |
||
15 | /** string Character group matching regexp pattern matching group name */ |
||
16 | const PATTERN_GROUP = 'fixed'; |
||
17 | |||
18 | /** string Regular expression matching character group */ |
||
19 | const PATTERN_REGEXP = '[^{}]+'; |
||
20 | |||
21 | /** string Character group matching regexp pattern */ |
||
22 | const PATTERN = '(?<'.self::PATTERN_GROUP.'>'.self::PATTERN_REGEXP.')'; |
||
23 | |||
24 | /** |
||
25 | * @inheritdoc |
||
26 | */ |
||
27 | 3 | protected function compareLength(AbstractCharacterGroup $group): int |
|
34 | } |
||
35 |
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.