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 $pluginParameters; |
||
10 | private $languageOrderCache = array(); |
||
11 | |||
12 | const DEFAULT_PROPERTY_ORDER = array("rdf:type", "dc:isReplacedBy", |
||
13 | "skos:definition", "skos:broader", "isothes:broaderGeneric", |
||
14 | "isothes:broaderPartitive", "isothes:broaderInstantial", |
||
15 | "skos:narrower", "isothes:narrowerGeneric", "isothes:narrowerPartitive", |
||
16 | "isothes:narrowerInstantial", "skos:related", "skos:altLabel", |
||
17 | "skos:note", "skos:scopeNote", "skos:historyNote", "rdfs:comment", |
||
18 | "dc11:source", "dc:source", "skosmos:memberOf", "skosmos:memberOfArray"); |
||
19 | |||
20 | const ISO25964_PROPERTY_ORDER = array("rdf:type", "dc:isReplacedBy", |
||
21 | // ISO 25964 allows placing all text fields (inc. SN and DEF) together |
||
22 | // so we will do that, except for HN, which is clearly administrative |
||
23 | "skos:note", "skos:scopeNote", "skos:definition", "rdfs:comment", |
||
24 | "dc11:source", "dc:source", "skos:altLabel", "skos:broader", |
||
25 | "isothes:broaderGeneric", "isothes:broaderPartitive", |
||
26 | "isothes:broaderInstantial", "skos:narrower", "isothes:narrowerGeneric", |
||
27 | "isothes:narrowerPartitive", "isothes:narrowerInstantial", |
||
28 | "skos:related", "skos:historyNote", "skosmos:memberOf", |
||
29 | "skosmos:memberOfArray"); |
||
30 | |||
31 | public function __construct($resource, $globalPlugins=array()) |
||
70 | |||
71 | /** |
||
72 | * Get the default language of this vocabulary |
||
73 | * @return string default language, e.g. 'en' |
||
74 | */ |
||
75 | |||
76 | public function getDefaultLanguage() |
||
91 | |||
92 | /** |
||
93 | * Whether the alphabetical index is small enough to be shown all at once. |
||
94 | * @return boolean true if all concepts can be shown at once. |
||
95 | */ |
||
96 | public function getAlphabeticalFull() |
||
100 | |||
101 | /** |
||
102 | * Returns a short name for a vocabulary if configured. If that has not been set |
||
103 | * using vocabId as a fallback. |
||
104 | * @return string |
||
105 | */ |
||
106 | public function getShortName() |
||
115 | |||
116 | /** |
||
117 | * Get the vocabulary feedback e-mail address and return it. |
||
118 | * |
||
119 | * @return string e-mail address or null if not defined. |
||
120 | */ |
||
121 | public function getFeedbackRecipient() |
||
126 | |||
127 | /** |
||
128 | * Returns the human readable vocabulary title. |
||
129 | * @return string the title of the vocabulary |
||
130 | */ |
||
131 | public function getTitle($lang = null) |
||
135 | |||
136 | /** |
||
137 | * Returns a boolean value set in the config.ttl config. |
||
138 | * @return boolean |
||
139 | */ |
||
140 | public function sortByNotation() |
||
144 | |||
145 | /** |
||
146 | * Returns a boolean value set in the config.ttl config. |
||
147 | * @return boolean |
||
148 | */ |
||
149 | public function showChangeList() |
||
153 | |||
154 | /** |
||
155 | * get the URLs from which the vocabulary data can be downloaded |
||
156 | * @return array Array with MIME type as key, URL as value |
||
157 | */ |
||
158 | public function getDataURLs() |
||
200 | |||
201 | /** |
||
202 | * Returns the main Concept Scheme URI of that Vocabulary, |
||
203 | * or null if not set. |
||
204 | * @return string concept scheme URI or null |
||
205 | */ |
||
206 | |||
207 | public function getMainConceptSchemeURI() |
||
216 | |||
217 | /** |
||
218 | * Returns the class URI used for concept groups in this vocabulary, |
||
219 | * or null if not set. |
||
220 | * @return string group class URI or null |
||
221 | */ |
||
222 | |||
223 | public function getGroupClassURI() |
||
232 | |||
233 | /** |
||
234 | * Returns the class URI used for thesaurus arrays in this vocabulary, |
||
235 | * or null if not set. |
||
236 | * @return string array class URI or null |
||
237 | */ |
||
238 | |||
239 | public function getArrayClassURI() |
||
248 | |||
249 | /** |
||
250 | * Returns custom properties displayed on the search page if configured. |
||
251 | * @return array array class URI or null |
||
252 | */ |
||
253 | |||
254 | View Code Duplication | public function getAdditionalSearchProperties() |
|
269 | |||
270 | /** |
||
271 | * Queries whether the property should be shown with all the label language variations. |
||
272 | * @param string $property |
||
273 | * @return boolean |
||
274 | */ |
||
275 | public function hasMultiLingualProperty($property) |
||
292 | |||
293 | /** |
||
294 | * Returns a boolean value set in the config.ttl config. |
||
295 | * @return boolean |
||
296 | */ |
||
297 | public function getShowHierarchy() |
||
301 | |||
302 | /** |
||
303 | * Returns a boolean value set in the config.ttl config. |
||
304 | * @return boolean |
||
305 | */ |
||
306 | public function showConceptSchemesInHierarchy() |
||
310 | |||
311 | /** |
||
312 | * Returns a boolean value set in the config.ttl config. |
||
313 | * @return boolean defaults to true if fetching hasn't been explicitly denied. |
||
314 | */ |
||
315 | public function getExternalResourcesLoading() |
||
319 | |||
320 | /** |
||
321 | * Returns a boolean value set in the config.ttl config. |
||
322 | * @return boolean |
||
323 | */ |
||
324 | public function getShowLangCodes() |
||
328 | |||
329 | /** |
||
330 | * Returns a boolean value set in the config.ttl config. |
||
331 | * @return boolean |
||
332 | */ |
||
333 | public function searchByNotation() |
||
337 | |||
338 | /** |
||
339 | * Returns skosmos:marcSourcecode value set in config.ttl. |
||
340 | * @return string marcsource name |
||
341 | */ |
||
342 | public function getMarcSourceCode($lang = null) |
||
346 | |||
347 | /** |
||
348 | * Returns a boolean value set in the config.ttl config. |
||
349 | * @return array array of concept class URIs (can be empty) |
||
350 | */ |
||
351 | public function getIndexClasses() |
||
355 | |||
356 | /** |
||
357 | * Returns skosmos:externalProperty values set in the config.ttl config. |
||
358 | * @return array array of external property URIs (can be empty) |
||
359 | */ |
||
360 | public function getExtProperties() |
||
364 | |||
365 | /** |
||
366 | * Get the languages supported by this vocabulary |
||
367 | * @return array languages supported by this vocabulary (as language tag strings) |
||
368 | */ |
||
369 | public function getLanguages() |
||
381 | |||
382 | /** |
||
383 | * Returns the plugin parameters |
||
384 | * @return string plugin parameters or null |
||
385 | */ |
||
386 | public function getPluginParameters() { |
||
389 | |||
390 | /** |
||
391 | * Returns the vocabulary default sidebar view. |
||
392 | * @return string name of the view |
||
393 | */ |
||
394 | public function getDefaultSidebarView() |
||
413 | |||
414 | /** |
||
415 | * Extracts the vocabulary id string from the baseuri of the vocabulary. |
||
416 | * @return string identifier eg. 'mesh'. |
||
417 | */ |
||
418 | public function getId() |
||
432 | |||
433 | public function getShowStatistics() { |
||
436 | |||
437 | public function getPlugins() |
||
441 | |||
442 | /** |
||
443 | * Returns the property/properties used for visualizing concept hierarchies. |
||
444 | * @return array array class URI or null |
||
445 | */ |
||
446 | |||
447 | View Code Duplication | public function getHierarchyProperty() |
|
462 | |||
463 | /** |
||
464 | * Returns a boolean value set in the config.ttl config. |
||
465 | * @return boolean |
||
466 | */ |
||
467 | public function showNotation() |
||
471 | |||
472 | /** |
||
473 | * Returns a boolean value set in the config.ttl config. |
||
474 | * @return boolean |
||
475 | */ |
||
476 | public function showAlphabeticalIndex() |
||
480 | |||
481 | /** |
||
482 | * Returns the alphabetical list qualifier in this vocabulary, |
||
483 | * or null if not set. |
||
484 | * @return EasyRdf\Resource|null alphabetical list qualifier resource or null |
||
485 | */ |
||
486 | public function getAlphabeticalListQualifier() |
||
490 | |||
491 | /** |
||
492 | * Returns a boolean value set in the config.ttl config. |
||
493 | * @return boolean |
||
494 | */ |
||
495 | public function getShowDeprecated() |
||
499 | |||
500 | /** |
||
501 | * Returns a boolean value set in the config.ttl config. |
||
502 | * @return boolean |
||
503 | */ |
||
504 | public function getShowDeprecatedChanges() |
||
508 | |||
509 | /** |
||
510 | * Returns the vocabulary dc:type value(s) with their labels and uris, if set in the vocabulary configuration. |
||
511 | * @return array of objects or an empty array |
||
512 | */ |
||
513 | public function getTypes($lang = null) |
||
524 | |||
525 | /** |
||
526 | * Returns an array of fallback languages that is ordered by priority and |
||
527 | * defined in the vocabulary configuration as a collection. |
||
528 | * Additionally, the chosen content language is inserted with the highest priority |
||
529 | * and the vocab default language is inserted with the lowest priority. |
||
530 | * @param string $clang |
||
531 | * @return array of language code strings |
||
532 | */ |
||
533 | public function getLanguageOrder($clang) |
||
557 | |||
558 | /** |
||
559 | * @return boolean |
||
560 | */ |
||
561 | public function isUseModifiedDate() |
||
565 | |||
566 | /** |
||
567 | * @return array |
||
568 | */ |
||
569 | public function getPropertyOrder() |
||
597 | } |
||
598 |
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: