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 |
||
20 | class ExceptionConversion extends Gateway |
||
21 | { |
||
22 | /** |
||
23 | * The wrapped gateway. |
||
24 | * |
||
25 | * @var Gateway |
||
26 | */ |
||
27 | protected $innerGateway; |
||
28 | |||
29 | /** |
||
30 | * Creates a new exception conversion gateway around $innerGateway. |
||
31 | * |
||
32 | * @param Gateway $innerGateway |
||
33 | */ |
||
34 | public function __construct(Gateway $innerGateway) |
||
38 | |||
39 | /** |
||
40 | * Inserts the given $language. |
||
41 | * |
||
42 | * @param Language $language |
||
43 | * |
||
44 | * @return int ID of the new language |
||
45 | */ |
||
46 | public function insertLanguage(Language $language) |
||
56 | |||
57 | /** |
||
58 | * Updates the data of the given $language. |
||
59 | * |
||
60 | * @param Language $language |
||
61 | */ |
||
62 | public function updateLanguage(Language $language) |
||
72 | |||
73 | /** |
||
74 | * {@inheritdoc} |
||
75 | */ |
||
76 | View Code Duplication | public function loadLanguageListData(array $ids): iterable |
|
86 | |||
87 | /** |
||
88 | * {@inheritdoc} |
||
89 | */ |
||
90 | View Code Duplication | public function loadLanguageListDataByLanguageCode(array $languageCodes): iterable |
|
100 | |||
101 | /** |
||
102 | * Loads the data for all languages. |
||
103 | * |
||
104 | * @return string[][] |
||
105 | */ |
||
106 | View Code Duplication | public function loadAllLanguagesData() |
|
116 | |||
117 | /** |
||
118 | * Deletes the language with $id. |
||
119 | * |
||
120 | * @param int $id |
||
121 | */ |
||
122 | View Code Duplication | public function deleteLanguage($id) |
|
132 | |||
133 | /** |
||
134 | * Check whether a language may be deleted. |
||
135 | * |
||
136 | * @param int $id |
||
137 | * |
||
138 | * @return bool |
||
139 | */ |
||
140 | View Code Duplication | public function canDeleteLanguage($id) |
|
150 | } |
||
151 |