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 |
||
7 | final class ReplacedShortcode extends AbstractShortcode |
||
8 | { |
||
9 | /** @var string */ |
||
10 | private $replacement; |
||
11 | /** @var string */ |
||
12 | private $text; |
||
13 | /** @var int */ |
||
14 | private $offset; |
||
15 | |||
16 | /** @param string $replacement */ |
||
17 | 58 | View Code Duplication | public function __construct(ParsedShortcodeInterface $shortcode, $replacement) |
28 | |||
29 | /** |
||
30 | * @param string $replacement |
||
31 | * |
||
32 | * @return self |
||
33 | */ |
||
34 | 1 | public function withReplacement($replacement) |
|
41 | |||
42 | /** @return string */ |
||
43 | 58 | public function getReplacement() |
|
47 | |||
48 | /** @return string */ |
||
49 | 58 | public function getText() |
|
53 | |||
54 | /** @return int */ |
||
55 | 58 | public function getOffset() |
|
59 | } |
||
60 |
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.