Complex classes like Vocabulary 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 Vocabulary, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 11 | class Vocabulary extends DataObject |
||
|
|
|||
| 12 | { |
||
| 13 | /** cached value of URI space */ |
||
| 14 | private $urispace = null; |
||
| 15 | private $config; |
||
| 16 | |||
| 17 | public function __construct($model, $resource) |
||
| 22 | |||
| 23 | /** |
||
| 24 | * Returns the VocabularyConfig object |
||
| 25 | * @return VocabularyConfig |
||
| 26 | */ |
||
| 27 | public function getConfig() |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Get the SPARQL endpoint URL for this vocabulary |
||
| 34 | * |
||
| 35 | * @return string endpoint URL |
||
| 36 | */ |
||
| 37 | public function getEndpoint() |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Get the SPARQL graph URI for this vocabulary |
||
| 44 | * |
||
| 45 | * @return string graph URI |
||
| 46 | */ |
||
| 47 | public function getGraph() |
||
| 56 | |||
| 57 | /** |
||
| 58 | * Get the SPARQL implementation for this vocabulary |
||
| 59 | * |
||
| 60 | * @return Sparql SPARQL object |
||
| 61 | */ |
||
| 62 | public function getSparql() |
||
| 71 | |||
| 72 | /** |
||
| 73 | * Get the URI space of concepts in this vocabulary. |
||
| 74 | * |
||
| 75 | * @return string full URI of concept |
||
| 76 | */ |
||
| 77 | public function getUriSpace() |
||
| 86 | |||
| 87 | /** |
||
| 88 | * Get the full URI of a concept in a vocabulary. If the passed local |
||
| 89 | * name is already a full URI, return it unchanged. |
||
| 90 | * |
||
| 91 | * @param $lname string local name of concept |
||
| 92 | * @return string full URI of concept |
||
| 93 | */ |
||
| 94 | public function getConceptURI($lname) |
||
| 102 | |||
| 103 | /** |
||
| 104 | * Asks the sparql implementation to make a label query for a uri. |
||
| 105 | * @param string $uri |
||
| 106 | * @param string $lang |
||
| 107 | */ |
||
| 108 | public function getConceptLabel($uri, $lang) |
||
| 112 | |||
| 113 | /** |
||
| 114 | * Get the localname of a concept in the vocabulary. If the URI is not |
||
| 115 | * in the URI space of this vocabulary, return the full URI. |
||
| 116 | * |
||
| 117 | * @param $uri string full URI of concept |
||
| 118 | * @return string local name of concept, or original full URI if the local name cannot be determined |
||
| 119 | */ |
||
| 120 | public function getLocalName($uri) |
||
| 124 | |||
| 125 | /** |
||
| 126 | * Retrieves all the information about the Vocabulary |
||
| 127 | * from the SPARQL-endpoint. |
||
| 128 | */ |
||
| 129 | public function getInfo($lang = null) |
||
| 202 | |||
| 203 | /** |
||
| 204 | * Return all concept schemes in the vocabulary. |
||
| 205 | * @return array Array with concept scheme URIs (string) as keys and labels (string) as values |
||
| 206 | */ |
||
| 207 | |||
| 208 | public function getConceptSchemes($lang = '') |
||
| 216 | |||
| 217 | /** |
||
| 218 | * Return the URI of the default concept scheme of this vocabulary. If the skosmos:mainConceptScheme property is set in the |
||
| 219 | * vocabulary configuration, that will be returned. Otherwise an arbitrary concept scheme will be returned. |
||
| 220 | * @return string concept scheme URI |
||
| 221 | */ |
||
| 222 | |||
| 223 | public function getDefaultConceptScheme() |
||
| 237 | |||
| 238 | /** |
||
| 239 | * Return the top concepts of a concept scheme in the vocabulary. |
||
| 240 | * @param string $conceptScheme URI of concept scheme whose top concepts to return. If not set, |
||
| 241 | * the default concept scheme of the vocabulary will be used. |
||
| 242 | * @param string $lang preferred language for the concept labels, |
||
| 243 | * @return array Array with concept URIs (string) as keys and labels (string) as values |
||
| 244 | */ |
||
| 245 | |||
| 246 | public function getTopConcepts($conceptScheme = null, $lang = '') |
||
| 258 | |||
| 259 | /** |
||
| 260 | * Tries to parse version, date and time from sparql version information into a readable format. |
||
| 261 | * @param string $version |
||
| 262 | * @return string |
||
| 263 | */ |
||
| 264 | private function parseVersionInfo($version) |
||
| 276 | |||
| 277 | /** |
||
| 278 | * Counts the statistics of the vocabulary. |
||
| 279 | * @return array of the concept counts in different languages |
||
| 280 | */ |
||
| 281 | public function getStatistics($lang = '') |
||
| 287 | |||
| 288 | /** |
||
| 289 | * Counts the statistics of the vocabulary. |
||
| 290 | * @return array of the concept counts in different languages |
||
| 291 | */ |
||
| 292 | public function getLabelStatistics() |
||
| 301 | |||
| 302 | /** |
||
| 303 | * Gets the parent concepts of a concept and child concepts for all of those. |
||
| 304 | * @param string $uri |
||
| 305 | * @param string $lang language identifier. |
||
| 306 | */ |
||
| 307 | public function getConceptHierarchy($uri, $lang) |
||
| 313 | |||
| 314 | /** |
||
| 315 | * Gets the child relations of a concept and whether these children have more children. |
||
| 316 | * @param string $uri |
||
| 317 | */ |
||
| 318 | public function getConceptChildren($uri, $lang) |
||
| 324 | |||
| 325 | /** |
||
| 326 | * Gets the skos:narrower relations of a concept. |
||
| 327 | * @param string $uri |
||
| 328 | * @param string $lang language identifier. |
||
| 329 | */ |
||
| 330 | public function getConceptNarrowers($uri, $lang) |
||
| 335 | |||
| 336 | /** |
||
| 337 | * Gets the skos:narrowerTransitive relations of a concept. |
||
| 338 | * @param string $uri |
||
| 339 | * @param integer $limit |
||
| 340 | * @param string $lang language identifier. |
||
| 341 | */ |
||
| 342 | public function getConceptTransitiveNarrowers($uri, $limit, $lang) |
||
| 347 | |||
| 348 | /** |
||
| 349 | * Gets the skos:broader relations of a concept. |
||
| 350 | * @param string $uri |
||
| 351 | * @param string $lang language identifier. |
||
| 352 | */ |
||
| 353 | public function getConceptBroaders($uri, $lang) |
||
| 358 | |||
| 359 | /** |
||
| 360 | * Gets the skos:broaderTransitive relations of a concept. |
||
| 361 | * @param string $uri |
||
| 362 | * @param integer $limit |
||
| 363 | * @param boolean $any set to true if you want to have a label even in case of a correct language one missing. |
||
| 364 | * @param string $lang language identifier. |
||
| 365 | */ |
||
| 366 | public function getConceptTransitiveBroaders($uri, $limit, $any = false, $lang) |
||
| 372 | |||
| 373 | /** |
||
| 374 | * Gets all the skos:related concepts of a concept. |
||
| 375 | * @param string $uri |
||
| 376 | * @param string $lang language identifier. |
||
| 377 | */ |
||
| 378 | public function getConceptRelateds($uri, $lang) |
||
| 383 | |||
| 384 | /** |
||
| 385 | * Makes a query into the sparql endpoint for a concept. |
||
| 386 | * @param string $uri the full URI of the concept |
||
| 387 | * @return array |
||
| 388 | */ |
||
| 389 | public function getConceptInfo($uri, $clang) |
||
| 395 | |||
| 396 | /** |
||
| 397 | * Lists the different concept groups available in the vocabulary. |
||
| 398 | * @param string $clang content language parameter |
||
| 399 | * @return array |
||
| 400 | */ |
||
| 401 | public function listConceptGroups($clang = null) |
||
| 420 | |||
| 421 | /** |
||
| 422 | * Lists the concepts available in the concept group. |
||
| 423 | * @param $clname |
||
| 424 | * @return array |
||
| 425 | */ |
||
| 426 | public function listConceptGroupContents($glname, $clang) |
||
| 446 | |||
| 447 | /** |
||
| 448 | * Returns the letters of the alphabet which have been used in this vocabulary. |
||
| 449 | * The returned letters may also include specials such as '0-9' (digits) and '!*' (special characters). |
||
| 450 | * @param $clang content language |
||
| 451 | * @return array array of letters |
||
| 452 | */ |
||
| 453 | public function getAlphabet($clang) |
||
| 479 | |||
| 480 | /** |
||
| 481 | * Searches for concepts with a label starting with the specified letter. |
||
| 482 | * Also the special tokens '0-9' (digits), '!*' (special characters) and '*' |
||
| 483 | * (everything) are supported. |
||
| 484 | * @param $letter letter (or special token) to search for |
||
| 485 | */ |
||
| 486 | public function searchConceptsAlphabetical($letter, $limit = null, $offset = null, $clang = null) |
||
| 490 | |||
| 491 | /** |
||
| 492 | * Makes a query for the transitive broaders of a concept and returns the concepts hierarchy processed for the view. |
||
| 493 | * @param string $lang |
||
| 494 | * @param string $uri |
||
| 495 | */ |
||
| 496 | public function getBreadCrumbs($lang, $uri) |
||
| 502 | |||
| 503 | /** |
||
| 504 | * Takes the crumbs as a parameter and combines the crumbs if the path they form is too long. |
||
| 505 | * @return array |
||
| 506 | */ |
||
| 507 | private function combineCrumbs($origCrumbs) |
||
| 528 | |||
| 529 | /** |
||
| 530 | * Recursive function for building the breadcrumb paths for the view. |
||
| 531 | * @param array $bT contains the results of the broaderTransitive query. |
||
| 532 | * @param string $uri |
||
| 533 | * @param array $path |
||
| 534 | */ |
||
| 535 | private function getCrumbs($bT, $uri, $path = null) |
||
| 574 | |||
| 575 | /** |
||
| 576 | * Verify that the requested language is supported by the vocabulary. If not, returns |
||
| 577 | * the default language of the vocabulary. |
||
| 578 | * @param string $lang language to check |
||
| 579 | * @return string language tag that is supported by the vocabulary |
||
| 580 | */ |
||
| 581 | |||
| 582 | public function verifyVocabularyLanguage($lang) |
||
| 586 | |||
| 587 | /** |
||
| 588 | * Returns a list of recently changed or entirely new concepts. |
||
| 589 | * @param string $clang content language for the labels |
||
| 590 | * @param string $lang UI language for the dates |
||
| 591 | * @return Array |
||
| 592 | */ |
||
| 593 | public function getChangeList($prop, $clang, $lang, $offset) |
||
| 603 | |||
| 604 | public function getTitle($lang=null) { |
||
| 607 | |||
| 608 | public function getShortName() { |
||
| 611 | |||
| 612 | public function getId() { |
||
| 615 | } |
||
| 616 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.