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 |
||
13 | class AddFile extends AbstractApi |
||
14 | { |
||
15 | /** |
||
16 | * @var Translation[] |
||
17 | */ |
||
18 | protected $translations; |
||
19 | |||
20 | /** |
||
21 | * @var string |
||
22 | */ |
||
23 | protected $type; |
||
24 | |||
25 | protected $branch; |
||
26 | |||
27 | /** |
||
28 | * @return mixed |
||
29 | * |
||
30 | * @throws \InvalidArgumentException |
||
31 | */ |
||
32 | public function execute() |
||
67 | |||
68 | /** |
||
69 | * @param string $localPath |
||
70 | * @param string $crowdinPath |
||
71 | * @param string $exportPattern |
||
72 | * @param string $title |
||
73 | * |
||
74 | * @return $this |
||
75 | */ |
||
76 | View Code Duplication | public function addTranslation($localPath, $crowdinPath, $exportPattern = null, $title = null) |
|
86 | |||
87 | /** |
||
88 | * @return Translation[] |
||
89 | */ |
||
90 | public function getTranslations() |
||
94 | |||
95 | /** |
||
96 | * @return string |
||
97 | */ |
||
98 | public function getType() |
||
102 | |||
103 | /** |
||
104 | * @param string $type |
||
105 | */ |
||
106 | public function setType($type) |
||
110 | |||
111 | /** |
||
112 | * @return string|null |
||
113 | */ |
||
114 | public function getBranch() |
||
118 | |||
119 | /** |
||
120 | * @param string $branch |
||
121 | */ |
||
122 | public function setBranch($branch) |
||
126 | } |
||
127 |
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.