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 |
||
13 | trait RawHtmlTrait |
||
14 | { |
||
15 | /** |
||
16 | * @var bool whether to support raw html blocks. |
||
17 | * Defaults to `false`. |
||
18 | */ |
||
19 | public $useRawHtml = false; |
||
20 | |||
21 | /** |
||
22 | * @var callable output filter |
||
23 | * Defaults to null. |
||
24 | */ |
||
25 | public $rawHtmlFilter = null; |
||
26 | |||
27 | /** |
||
28 | * identify a line as the beginning of a raw html block. |
||
29 | */ |
||
30 | 23 | protected function identifyRawHtml($line) |
|
34 | |||
35 | /** |
||
36 | * Consume lines for a raw html block |
||
37 | */ |
||
38 | 1 | View Code Duplication | protected function consumeRawHtml($lines, $current) |
56 | |||
57 | /** |
||
58 | * Renders a raw html block |
||
59 | */ |
||
60 | 1 | protected function renderRawHtml($block) |
|
68 | } |
||
69 |
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.