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 |
||
9 | View Code Duplication | abstract class Build implements BuildInterface |
|
|
|||
10 | { |
||
11 | use TransportAwareTrait; |
||
12 | |||
13 | /** |
||
14 | * @var int |
||
15 | */ |
||
16 | protected $id; |
||
17 | |||
18 | /** |
||
19 | * @var int |
||
20 | */ |
||
21 | protected $repository_id; |
||
22 | |||
23 | /** |
||
24 | * @var int |
||
25 | */ |
||
26 | protected $commit_id; |
||
27 | |||
28 | /** |
||
29 | * @var string |
||
30 | */ |
||
31 | protected $number; |
||
32 | |||
33 | /** |
||
34 | * @var bool |
||
35 | */ |
||
36 | protected $pull_request; |
||
37 | |||
38 | /** |
||
39 | * @var string |
||
40 | */ |
||
41 | protected $pull_request_title; |
||
42 | |||
43 | /** |
||
44 | * @var int |
||
45 | */ |
||
46 | protected $pull_request_number; |
||
47 | |||
48 | /** |
||
49 | * @var array |
||
50 | */ |
||
51 | protected $config = []; |
||
52 | |||
53 | /** |
||
54 | * @var string |
||
55 | */ |
||
56 | protected $state; |
||
57 | |||
58 | /** |
||
59 | * @var DateTimeInterface |
||
60 | */ |
||
61 | protected $started_at; |
||
62 | |||
63 | /** |
||
64 | * @var DateTimeInterface |
||
65 | */ |
||
66 | protected $finished_at; |
||
67 | |||
68 | /** |
||
69 | * @var int |
||
70 | */ |
||
71 | protected $duration; |
||
72 | |||
73 | /** |
||
74 | * @var int[] |
||
75 | */ |
||
76 | protected $job_ids = []; |
||
77 | |||
78 | 2 | public function id() : int |
|
82 | |||
83 | 2 | public function repositoryId() : int |
|
87 | |||
88 | 2 | public function commitId() : int |
|
92 | |||
93 | 2 | public function number() : int |
|
97 | |||
98 | 2 | public function pullRequest() : bool |
|
102 | |||
103 | 2 | public function pullRequestTitle() : string |
|
107 | |||
108 | 2 | public function pullRequestNumber() : int |
|
112 | |||
113 | 2 | public function config() : array |
|
117 | |||
118 | 2 | public function state() : string |
|
122 | |||
123 | 2 | public function startedAt() : DateTimeInterface |
|
127 | |||
128 | 2 | public function finishedAt() : DateTimeInterface |
|
132 | |||
133 | 2 | public function duration() : int |
|
137 | |||
138 | 2 | public function jobIds() : array |
|
142 | |||
143 | public function refresh() |
||
147 | } |
||
148 |
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.