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 |
||
8 | class DatumboxAPI |
||
9 | { |
||
10 | const version='1.0'; |
||
11 | |||
12 | protected $api_key; |
||
13 | |||
14 | /** |
||
15 | * Constructor |
||
16 | * |
||
17 | * @param string $api_key |
||
18 | * @return DatumboxAPI |
||
|
|||
19 | */ |
||
20 | public function __construct($api_key) |
||
24 | |||
25 | /** |
||
26 | * Calls the Web Service of Datumbox |
||
27 | * |
||
28 | * @param string $api_method |
||
29 | * @param array $POSTparameters |
||
30 | * |
||
31 | * @return string $jsonreply |
||
32 | */ |
||
33 | protected function CallWebService($api_method,$POSTparameters) |
||
51 | |||
52 | /** |
||
53 | * Parses the API Reply |
||
54 | * |
||
55 | * @param mixed $jsonreply |
||
56 | * |
||
57 | * @return mixed |
||
58 | */ |
||
59 | protected function ParseReply($jsonreply) |
||
73 | |||
74 | /** |
||
75 | * Performs Sentiment Analysis. |
||
76 | * |
||
77 | * @param string $text The clear text (no HTML tags) that we evaluate. |
||
78 | * |
||
79 | * @return string|false It returns "positive", "negative" or "neutral" on success and false on fail. |
||
80 | */ |
||
81 | View Code Duplication | public function SentimentAnalysis($text) |
|
91 | |||
92 | /** |
||
93 | * Performs Sentiment Analysis on Twitter. |
||
94 | * |
||
95 | * @param string $text The text of the tweet that we evaluate. |
||
96 | * |
||
97 | * @return string|false It returns "positive", "negative" or "neutral" on success and false on fail. |
||
98 | */ |
||
99 | View Code Duplication | public function TwitterSentimentAnalysis($text) |
|
109 | |||
110 | /** |
||
111 | * Performs Subjectivity Analysis. |
||
112 | * |
||
113 | * @param string $text The clear text (no HTML tags) that we evaluate. |
||
114 | * |
||
115 | * @return string|false. It returns "objective" or "subjective" on success and false on fail. |
||
116 | */ |
||
117 | View Code Duplication | public function SubjectivityAnalysis($text) |
|
127 | |||
128 | /** |
||
129 | * Performs Topic Classification. |
||
130 | * |
||
131 | * @param string $text The clear text (no HTML tags) that we evaluate. |
||
132 | * |
||
133 | * @return string|false. It returns "Arts", "Business & Economy", "Computers & Technology", "Health", "Home & Domestic Life", "News", "Recreation & Activities", "Reference & Education", "Science", "Shopping", "Society", "Sports" on success and false on fail. |
||
134 | */ |
||
135 | View Code Duplication | public function TopicClassification($text) |
|
145 | |||
146 | /** |
||
147 | * Performs Spam Detection. |
||
148 | * |
||
149 | * @param string $text The clear text (no HTML tags) that we evaluate. |
||
150 | * |
||
151 | * @return string|false It returns "spam" or "nospam" on success and false on fail. |
||
152 | */ |
||
153 | View Code Duplication | public function SpamDetection($text) |
|
163 | |||
164 | /** |
||
165 | * Performs Adult Content Detection. |
||
166 | * |
||
167 | * @param string $text The clear text (no HTML tags) that we evaluate. |
||
168 | * |
||
169 | * @return string|false It returns "adult" or "noadult" on success and false on fail. |
||
170 | */ |
||
171 | View Code Duplication | public function AdultContentDetection($text) |
|
181 | |||
182 | /** |
||
183 | * Performs Readability Assessment. |
||
184 | * |
||
185 | * @param string $text The clear text (no HTML tags) that we evaluate. |
||
186 | * |
||
187 | * @return string|false It returns "basic", "intermediate" or "advanced" on success and false on fail. |
||
188 | */ |
||
189 | View Code Duplication | public function ReadabilityAssessment($text) |
|
199 | |||
200 | /** |
||
201 | * Performs Language Detection. |
||
202 | * |
||
203 | * @param string $text The clear text (no HTML tags) that we evaluate. |
||
204 | * |
||
205 | * @return string|false It returns the ISO639-1 two-letter language code (http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) on success and false on fail. |
||
206 | */ |
||
207 | View Code Duplication | public function LanguageDetection($text) |
|
217 | |||
218 | /** |
||
219 | * Performs Commercial Detection. |
||
220 | * |
||
221 | * @param string $text The clear text (no HTML tags) that we evaluate. |
||
222 | * |
||
223 | * @return string|false It returns "commercial" or "noncommercial" on success and false on fail. |
||
224 | */ |
||
225 | View Code Duplication | public function CommercialDetection($text) |
|
235 | |||
236 | /** |
||
237 | * Performs Educational Detection. |
||
238 | * |
||
239 | * @param string $text The clear text (no HTML tags) that we evaluate. |
||
240 | * |
||
241 | * @return string|false It returns "educational" or "noneducational" on success and false on fail. |
||
242 | */ |
||
243 | View Code Duplication | public function EducationalDetection($text) |
|
253 | |||
254 | /** |
||
255 | * Performs Gender Detection. |
||
256 | * |
||
257 | * @param string $text The clear text (no HTML tags) that we evaluate. |
||
258 | * |
||
259 | * @return string|false It returns "male" or "female" on success and false on fail. |
||
260 | */ |
||
261 | View Code Duplication | public function GenderDetection($text) |
|
271 | |||
272 | /** |
||
273 | * Performs Text Extraction. It extracts the important information (clear text) from a given webpage. |
||
274 | * |
||
275 | * @param string $text The HTML of the webpage. |
||
276 | * |
||
277 | * @return string|false It returns the clear text of the document on success and false on fail. |
||
278 | */ |
||
279 | View Code Duplication | public function TextExtraction($text) |
|
289 | |||
290 | /** |
||
291 | * Performs Keyword Extraction. It extracts the keywords and keywords combinations from a text. |
||
292 | * |
||
293 | * @param string $text The clear text (no HTML tags) that we analyze. |
||
294 | * @param integer $n It is a number from 1 to 5 which denotes the number of Keyword combinations that we want to get. |
||
295 | * |
||
296 | * @return array|false It returns an array with the keywords of the document on success and false on fail. |
||
297 | */ |
||
298 | public function KeywordExtraction($text,$n) |
||
309 | |||
310 | /** |
||
311 | * Evaluates the Document Similarity between 2 documents. |
||
312 | * |
||
313 | * @param string $original The first clear text (no HTML tags) that we compare. |
||
314 | * @param string $copy The second clear text (no HTML tags) that we compare. |
||
315 | * |
||
316 | * @return array|false It returns an array with similarity metrics for the two documents on success and false on fail. |
||
317 | */ |
||
318 | public function DocumentSimilarity($original,$copy) |
||
329 | |||
330 | |||
331 | } |
||
332 | |||
333 |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.