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:
Complex classes like VocabularyConfig often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use VocabularyConfig, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
6 | class VocabularyConfig extends BaseConfig |
||
7 | { |
||
8 | private $plugins; |
||
9 | private $languageOrderCache = array(); |
||
10 | |||
11 | public function __construct($resource, $globalPlugins=array()) |
||
23 | |||
24 | /** |
||
25 | * Get the default language of this vocabulary |
||
26 | * @return string default language, e.g. 'en' |
||
27 | */ |
||
28 | |||
29 | public function getDefaultLanguage() |
||
44 | |||
45 | /** |
||
46 | * Wether the alphabetical index is small enough to be shown all at once. |
||
47 | * @return boolean true if all concepts can be shown at once. |
||
48 | */ |
||
49 | public function getAlphabeticalFull() |
||
53 | |||
54 | /** |
||
55 | * Returns a short name for a vocabulary if configured. If that has not been set |
||
56 | * using vocabId as a fallback. |
||
57 | * @return string |
||
58 | */ |
||
59 | public function getShortName() |
||
68 | |||
69 | /** |
||
70 | * Get the vocabulary feedback e-mail address and return it. |
||
71 | * |
||
72 | * @return string e-mail address or null if not defined. |
||
73 | */ |
||
74 | public function getFeedbackRecipient() |
||
79 | |||
80 | /** |
||
81 | * Returns the human readable vocabulary title. |
||
82 | * @return string the title of the vocabulary |
||
83 | */ |
||
84 | public function getTitle($lang = null) |
||
88 | |||
89 | /** |
||
90 | * Returns a boolean value set in the config.ttl config. |
||
91 | * @return boolean |
||
92 | */ |
||
93 | public function sortByNotation() |
||
97 | |||
98 | /** |
||
99 | * Returns a boolean value set in the config.ttl config. |
||
100 | * @return boolean |
||
101 | */ |
||
102 | public function showChangeList() |
||
106 | |||
107 | /** |
||
108 | * get the URLs from which the vocabulary data can be downloaded |
||
109 | * @return array Array with MIME type as key, URL as value |
||
110 | */ |
||
111 | public function getDataURLs() |
||
153 | |||
154 | /** |
||
155 | * Returns the main Concept Scheme URI of that Vocabulary, |
||
156 | * or null if not set. |
||
157 | * @return string concept scheme URI or null |
||
158 | */ |
||
159 | |||
160 | public function getMainConceptSchemeURI() |
||
169 | |||
170 | /** |
||
171 | * Returns the class URI used for concept groups in this vocabulary, |
||
172 | * or null if not set. |
||
173 | * @return string group class URI or null |
||
174 | */ |
||
175 | |||
176 | public function getGroupClassURI() |
||
185 | |||
186 | /** |
||
187 | * Returns the class URI used for thesaurus arrays in this vocabulary, |
||
188 | * or null if not set. |
||
189 | * @return string array class URI or null |
||
190 | */ |
||
191 | |||
192 | public function getArrayClassURI() |
||
201 | |||
202 | /** |
||
203 | * Returns custom properties displayed on the search page if configured. |
||
204 | * @return string array class URI or null |
||
205 | */ |
||
206 | |||
207 | View Code Duplication | public function getAdditionalSearchProperties() |
|
222 | |||
223 | /** |
||
224 | * Queries whether the property should be shown with all the label language variations. |
||
225 | * @param string $property |
||
226 | * @return boolean |
||
227 | */ |
||
228 | public function hasMultiLingualProperty($property) |
||
245 | |||
246 | /** |
||
247 | * Returns a boolean value set in the config.ttl config. |
||
248 | * @return boolean |
||
249 | */ |
||
250 | public function getShowHierarchy() |
||
254 | |||
255 | /** |
||
256 | * Returns a boolean value set in the config.ttl config. |
||
257 | * @return boolean |
||
258 | */ |
||
259 | public function showConceptSchemesInHierarchy() |
||
263 | |||
264 | /** |
||
265 | * Returns a boolean value set in the config.ttl config. |
||
266 | * @return boolean defaults to true if fetching hasn't been explicitly denied. |
||
267 | */ |
||
268 | public function getExternalResourcesLoading() |
||
272 | |||
273 | /** |
||
274 | * Returns a boolean value set in the config.ttl config. |
||
275 | * @return boolean |
||
276 | */ |
||
277 | public function getShowLangCodes() |
||
281 | |||
282 | /** |
||
283 | * Returns skosmos:marcSourcecode value set in config.ttl. |
||
284 | * @return string marcsource name |
||
285 | */ |
||
286 | public function getMarcSourceCode($lang = null) |
||
290 | |||
291 | /** |
||
292 | * Returns a boolean value set in the config.ttl config. |
||
293 | * @return array array of concept class URIs (can be empty) |
||
294 | */ |
||
295 | public function getIndexClasses() |
||
299 | |||
300 | /** |
||
301 | * Returns skosmos:externalProperty values set in the config.ttl config. |
||
302 | * @return array array of external property URIs (can be empty) |
||
303 | */ |
||
304 | public function getExtProperties() |
||
308 | |||
309 | /** |
||
310 | * Get the languages supported by this vocabulary |
||
311 | * @return array languages supported by this vocabulary (as language tag strings) |
||
312 | */ |
||
313 | public function getLanguages() |
||
325 | |||
326 | /** |
||
327 | * Returns the vocabulary default sidebar view. |
||
328 | * @return string name of the view |
||
329 | */ |
||
330 | public function getDefaultSidebarView() |
||
349 | |||
350 | /** |
||
351 | * Extracts the vocabulary id string from the baseuri of the vocabulary. |
||
352 | * @return string identifier eg. 'mesh'. |
||
353 | */ |
||
354 | public function getId() |
||
368 | |||
369 | public function getShowStatistics() { |
||
372 | |||
373 | public function getPlugins() |
||
377 | |||
378 | /** |
||
379 | * Returns the property/properties used for visualizing concept hierarchies. |
||
380 | * @return string array class URI or null |
||
381 | */ |
||
382 | |||
383 | View Code Duplication | public function getHierarchyProperty() |
|
398 | |||
399 | /** |
||
400 | * Returns a boolean value set in the config.ttl config. |
||
401 | * @return boolean |
||
402 | */ |
||
403 | public function showNotation() |
||
407 | |||
408 | /** |
||
409 | * Returns a boolean value set in the config.ttl config. |
||
410 | * @return boolean |
||
411 | */ |
||
412 | public function showAlphabeticalIndex() |
||
416 | |||
417 | /** |
||
418 | * Returns the alphabetical list qualifier in this vocabulary, |
||
419 | * or null if not set. |
||
420 | * @return EasyRdf\Resource|null alphabetical list qualifier resource or null |
||
421 | */ |
||
422 | public function getAlphabeticalListQualifier() |
||
426 | |||
427 | /** |
||
428 | * Returns a boolean value set in the config.ttl config. |
||
429 | * @return boolean |
||
430 | */ |
||
431 | public function getShowDeprecated() |
||
435 | |||
436 | /** |
||
437 | * Returns the vocabulary dc:type value(s) with their labels and uris, if set in the vocabulary configuration. |
||
438 | * @return array of objects or an empty array |
||
439 | */ |
||
440 | public function getTypes($lang = null) |
||
451 | |||
452 | /** |
||
453 | * Returns an array of fallback languages that is ordered by priority and |
||
454 | * defined in the vocabulary configuration as a collection. |
||
455 | * Additionally, the chosen content language is inserted with the highest priority |
||
456 | * and the vocab default language is inserted with the lowest priority. |
||
457 | * @param string $clang |
||
458 | * @return array of language code strings |
||
459 | */ |
||
460 | public function getLanguageOrder($clang) |
||
484 | |||
485 | /** |
||
486 | * Returns a boolean value set in the config.ttl config. |
||
487 | * @return boolean |
||
488 | */ |
||
489 | public function getUseModifiedDate(): bool |
||
493 | } |
||
494 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: