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 |
||
15 | class SeriesPosts extends PostListAbstract |
||
16 | { |
||
17 | // Param name to be used in URLs: ":series" |
||
18 | const URL_PARAM_NAME = 'series'; |
||
19 | |||
20 | const NAME = 'postsInSeries'; |
||
21 | |||
22 | /** |
||
23 | * @var Series |
||
24 | */ |
||
25 | public $series; |
||
26 | |||
27 | /** |
||
28 | * @var bool |
||
29 | */ |
||
30 | protected $includeTaggedPosts = false; |
||
31 | |||
32 | /** |
||
33 | * @return array |
||
34 | */ |
||
35 | public function componentDetails(): array |
||
42 | |||
43 | /** |
||
44 | * @return array |
||
45 | */ |
||
46 | View Code Duplication | public function defineProperties(): array |
|
64 | |||
65 | /** |
||
66 | * @inheritDoc |
||
67 | */ |
||
68 | protected function prepareVars(): void |
||
74 | |||
75 | /** |
||
76 | * @inheritDoc |
||
77 | */ |
||
78 | protected function prepareContextItem() |
||
85 | |||
86 | /** |
||
87 | * @return mixed |
||
88 | */ |
||
89 | protected function getPostsQuery() |
||
107 | |||
108 | protected function setPostUrl(Post $post) |
||
118 | } |
||
119 |
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.