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 declare(strict_types=1); |
||
15 | View Code Duplication | abstract class Directory extends AbstractResource implements DirectoryInterface |
|
|
|||
16 | { |
||
17 | /** |
||
18 | * @var string |
||
19 | */ |
||
20 | protected $type; |
||
21 | |||
22 | /** |
||
23 | * @var string |
||
24 | */ |
||
25 | protected $encoding; |
||
26 | |||
27 | /** |
||
28 | * @var int |
||
29 | */ |
||
30 | protected $size; |
||
31 | |||
32 | /** |
||
33 | * @var string |
||
34 | */ |
||
35 | protected $name; |
||
36 | |||
37 | /** |
||
38 | * @var string |
||
39 | */ |
||
40 | protected $path; |
||
41 | |||
42 | /** |
||
43 | * @var string |
||
44 | */ |
||
45 | protected $sha; |
||
46 | |||
47 | /** |
||
48 | * @var string |
||
49 | */ |
||
50 | protected $url; |
||
51 | |||
52 | /** |
||
53 | * @var string |
||
54 | */ |
||
55 | protected $git_url; |
||
56 | |||
57 | /** |
||
58 | * @var string |
||
59 | */ |
||
60 | protected $html_url; |
||
61 | |||
62 | /** |
||
63 | * @var string |
||
64 | */ |
||
65 | protected $download_url; |
||
66 | |||
67 | /** |
||
68 | * @var Contents\Links |
||
69 | */ |
||
70 | protected $_links; |
||
71 | |||
72 | /** |
||
73 | * @return string |
||
74 | */ |
||
75 | public function type() : string |
||
79 | |||
80 | /** |
||
81 | * @return string |
||
82 | */ |
||
83 | public function encoding() : string |
||
87 | |||
88 | /** |
||
89 | * @return int |
||
90 | */ |
||
91 | public function size() : int |
||
95 | |||
96 | /** |
||
97 | * @return string |
||
98 | */ |
||
99 | public function name() : string |
||
103 | |||
104 | /** |
||
105 | * @return string |
||
106 | */ |
||
107 | public function path() : string |
||
111 | |||
112 | /** |
||
113 | * @return string |
||
114 | */ |
||
115 | public function sha() : string |
||
119 | |||
120 | /** |
||
121 | * @return string |
||
122 | */ |
||
123 | public function url() : string |
||
127 | |||
128 | /** |
||
129 | * @return string |
||
130 | */ |
||
131 | public function gitUrl() : string |
||
135 | |||
136 | /** |
||
137 | * @return string |
||
138 | */ |
||
139 | public function htmlUrl() : string |
||
143 | |||
144 | /** |
||
145 | * @return string |
||
146 | */ |
||
147 | public function downloadUrl() : string |
||
151 | |||
152 | /** |
||
153 | * @return Contents\Links |
||
154 | */ |
||
155 | public function links() : Contents\Links |
||
159 | } |
||
160 |
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.