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 |
||
10 | class Render |
||
11 | { |
||
12 | public $media; |
||
13 | public $postmeta; |
||
14 | public $theme; |
||
15 | public $utility; |
||
16 | |||
17 | public function __construct( Media $media, PostMeta $postmeta, Theme $theme, Utility $utility ) |
||
24 | |||
25 | View Code Duplication | public function blockquote( $metaKey = false, array $attributes = [] ) |
|
34 | |||
35 | public function button( $postId = 0, $title = false ) |
||
49 | |||
50 | public function buttons( array $postIds = [] ) |
||
56 | |||
57 | public function content( $metaKey = false ) |
||
67 | |||
68 | public function gallery( array $args = [] ) |
||
72 | |||
73 | View Code Duplication | public function title( $metaKey = false, array $attributes = [] ) |
|
84 | |||
85 | public function video( $metaKey = 'video', $screenshotMetaKey = false ) |
||
88 | } |
||
89 |
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.