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 a boolean value set in the config.ttl config. |
||
| 284 | * @return boolean |
||
| 285 | */ |
||
| 286 | public function searchByNotation() |
||
| 290 | |||
| 291 | /** |
||
| 292 | * Returns skosmos:marcSourcecode value set in config.ttl. |
||
| 293 | * @return string marcsource name |
||
| 294 | */ |
||
| 295 | public function getMarcSourceCode($lang = null) |
||
| 299 | |||
| 300 | /** |
||
| 301 | * Returns a boolean value set in the config.ttl config. |
||
| 302 | * @return array array of concept class URIs (can be empty) |
||
| 303 | */ |
||
| 304 | public function getIndexClasses() |
||
| 308 | |||
| 309 | /** |
||
| 310 | * Returns skosmos:externalProperty values set in the config.ttl config. |
||
| 311 | * @return array array of external property URIs (can be empty) |
||
| 312 | */ |
||
| 313 | public function getExtProperties() |
||
| 317 | |||
| 318 | /** |
||
| 319 | * Get the languages supported by this vocabulary |
||
| 320 | * @return array languages supported by this vocabulary (as language tag strings) |
||
| 321 | */ |
||
| 322 | public function getLanguages() |
||
| 334 | |||
| 335 | /** |
||
| 336 | * Returns the vocabulary default sidebar view. |
||
| 337 | * @return string name of the view |
||
| 338 | */ |
||
| 339 | public function getDefaultSidebarView() |
||
| 358 | |||
| 359 | /** |
||
| 360 | * Extracts the vocabulary id string from the baseuri of the vocabulary. |
||
| 361 | * @return string identifier eg. 'mesh'. |
||
| 362 | */ |
||
| 363 | public function getId() |
||
| 377 | |||
| 378 | public function getShowStatistics() { |
||
| 381 | |||
| 382 | public function getPlugins() |
||
| 386 | |||
| 387 | /** |
||
| 388 | * Returns the property/properties used for visualizing concept hierarchies. |
||
| 389 | * @return string array class URI or null |
||
| 390 | */ |
||
| 391 | |||
| 392 | View Code Duplication | public function getHierarchyProperty() |
|
| 407 | |||
| 408 | /** |
||
| 409 | * Returns a boolean value set in the config.ttl config. |
||
| 410 | * @return boolean |
||
| 411 | */ |
||
| 412 | public function showNotation() |
||
| 416 | |||
| 417 | /** |
||
| 418 | * Returns a boolean value set in the config.ttl config. |
||
| 419 | * @return boolean |
||
| 420 | */ |
||
| 421 | public function showAlphabeticalIndex() |
||
| 425 | |||
| 426 | /** |
||
| 427 | * Returns the alphabetical list qualifier in this vocabulary, |
||
| 428 | * or null if not set. |
||
| 429 | * @return EasyRdf\Resource|null alphabetical list qualifier resource or null |
||
| 430 | */ |
||
| 431 | public function getAlphabeticalListQualifier() |
||
| 435 | |||
| 436 | /** |
||
| 437 | * Returns a boolean value set in the config.ttl config. |
||
| 438 | * @return boolean |
||
| 439 | */ |
||
| 440 | public function getShowDeprecated() |
||
| 444 | |||
| 445 | /** |
||
| 446 | * Returns the vocabulary dc:type value(s) with their labels and uris, if set in the vocabulary configuration. |
||
| 447 | * @return array of objects or an empty array |
||
| 448 | */ |
||
| 449 | public function getTypes($lang = null) |
||
| 460 | |||
| 461 | /** |
||
| 462 | * Returns an array of fallback languages that is ordered by priority and |
||
| 463 | * defined in the vocabulary configuration as a collection. |
||
| 464 | * Additionally, the chosen content language is inserted with the highest priority |
||
| 465 | * and the vocab default language is inserted with the lowest priority. |
||
| 466 | * @param string $clang |
||
| 467 | * @return array of language code strings |
||
| 468 | */ |
||
| 469 | public function getLanguageOrder($clang) |
||
| 493 | |||
| 494 | /** |
||
| 495 | * Returns a boolean value set in the config.ttl config. |
||
| 496 | * @return boolean |
||
| 497 | */ |
||
| 498 | public function getUseModifiedDate(): bool |
||
| 502 | } |
||
| 503 |
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: