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 | class Job implements JobInterface |
|
|
|||
10 | { |
||
11 | use TransportAwareTrait; |
||
12 | |||
13 | /** |
||
14 | * @var int |
||
15 | */ |
||
16 | protected $id; |
||
17 | |||
18 | /** |
||
19 | * @var int |
||
20 | */ |
||
21 | protected $build_id; |
||
22 | |||
23 | /** |
||
24 | * @var int |
||
25 | */ |
||
26 | protected $repository_id; |
||
27 | |||
28 | /** |
||
29 | * @var int |
||
30 | */ |
||
31 | protected $commit_id; |
||
32 | |||
33 | /** |
||
34 | * @var int |
||
35 | */ |
||
36 | protected $log_id; |
||
37 | |||
38 | /** |
||
39 | * @var string |
||
40 | */ |
||
41 | protected $number; |
||
42 | |||
43 | /** |
||
44 | * @var array |
||
45 | */ |
||
46 | protected $config = []; |
||
47 | |||
48 | /** |
||
49 | * @var string |
||
50 | */ |
||
51 | protected $state; |
||
52 | |||
53 | /** |
||
54 | * @var DateTimeInterface |
||
55 | */ |
||
56 | protected $started_at; |
||
57 | |||
58 | /** |
||
59 | * @var DateTimeInterface |
||
60 | */ |
||
61 | protected $finished_at; |
||
62 | |||
63 | /** |
||
64 | * @var string |
||
65 | */ |
||
66 | protected $queue; |
||
67 | |||
68 | /** |
||
69 | * @var bool |
||
70 | */ |
||
71 | protected $allow_failure; |
||
72 | |||
73 | /** |
||
74 | * @var int[] |
||
75 | */ |
||
76 | protected $annotation_ids; |
||
77 | |||
78 | 2 | public function id() : int |
|
79 | { |
||
80 | 2 | return $this->id; |
|
81 | } |
||
82 | |||
83 | public function buildId() : int |
||
87 | |||
88 | 2 | public function repositoryId() : int |
|
92 | |||
93 | 2 | public function commitId() : int |
|
97 | |||
98 | 2 | public function logId() : int |
|
102 | |||
103 | 2 | public function number() : string |
|
107 | |||
108 | 2 | public function config() : array |
|
112 | |||
113 | 2 | public function state() : string |
|
117 | |||
118 | 2 | public function startedAt() : DateTimeInterface |
|
122 | |||
123 | 2 | public function finishedAt() : DateTimeInterface |
|
127 | |||
128 | 2 | public function queue() : string |
|
132 | |||
133 | 2 | public function allowFailure() : bool |
|
137 | |||
138 | 2 | public function annotationIds() : 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.