| Total Complexity | 41 | 
| Total Lines | 245 | 
| Duplicated Lines | 0 % | 
| Changes | 1 | ||
| Bugs | 0 | Features | 0 | 
Complex classes like ConceptMappingPropertyValue 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.
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 ConceptMappingPropertyValue, and based on these observations, apply Extract Interface, too.
| 1 | <?php | ||
| 8 | class ConceptMappingPropertyValue extends VocabularyDataObject | ||
| 9 | { | ||
| 10 | /** property type */ | ||
| 11 | private $type; | ||
| 12 | private $source; | ||
| 13 | private $clang; | ||
| 14 | private $labelcache; | ||
| 15 | |||
| 16 | /** | ||
| 17 | * ConceptMappingPropertyValue constructor. | ||
| 18 | * | ||
| 19 | * @param Model $model | ||
| 20 | * @param Vocabulary $vocab Target vocabulary | ||
| 21 | * @param Resource $target Target concept resource | ||
| 22 | * @param Resource $source Source concept resource | ||
| 23 | * @param string $prop Mapping property | ||
| 24 | * @param ?string $clang Preferred label language (nullable) | ||
| 25 | */ | ||
| 26 | public function __construct(Model $model, Vocabulary $vocab, Resource $target, Resource $source, string $prop, $clang = '') | ||
| 27 |     { | ||
| 28 | parent::__construct($model, $vocab, $target); | ||
| 29 | $this->source = $source; | ||
| 30 | $this->type = $prop; | ||
| 31 | $this->clang = $clang; | ||
| 32 | $this->labelcache = array(); | ||
| 33 | } | ||
| 34 | |||
| 35 | public function __toString() | ||
| 36 |     { | ||
| 37 | $label = $this->getLabel(); | ||
| 38 | $notation = $this->getNotation(); | ||
| 39 | return ltrim($notation . ' ') . $label; | ||
| 40 | } | ||
| 41 | |||
| 42 | public function getType() | ||
| 45 | } | ||
| 46 | |||
| 47 | public function getLabel($lang = '', $queryExVocabs = true) | ||
| 56 | } | ||
| 57 | |||
| 58 | public function getSortKey() | ||
| 59 |     { | ||
| 60 | return strtolower($this->getVocabName() . ": " . $this->getLabel()); | ||
| 61 | } | ||
| 62 | |||
| 63 | private function queryLabel($lang = '', $queryExVocabs = true) | ||
| 64 |     { | ||
| 65 |         if ($this->clang) { | ||
| 66 | $lang = $this->clang; | ||
| 67 | } | ||
| 68 | |||
| 69 | |||
| 70 | $label = $this->getResourceLabel($this->resource, $lang); | ||
| 71 |         if ($label) { | ||
| 72 | return $label; | ||
| 73 | } | ||
| 74 | |||
| 75 | // if multiple vocabularies are found, the following method will return in priority the current vocabulary of the mapping | ||
| 76 | $exvocab = $queryExVocabs ? $this->model->guessVocabularyFromURI($this->resource->getUri(), $this->vocab->getId()) : null; | ||
| 77 | |||
| 78 | // if the resource is from another vocabulary known by the skosmos instance | ||
| 79 |         if ($exvocab) { | ||
| 80 | $label = $this->getExternalLabel($exvocab, $this->getUri(), $lang) ? $this->getExternalLabel($exvocab, $this->getUri(), $lang) : $this->getExternalLabel($exvocab, $this->getUri(), $exvocab->getConfig()->getDefaultLanguage()); | ||
| 81 |             if ($label) { | ||
| 82 | return $label; | ||
| 83 | } | ||
| 84 | } | ||
| 85 | |||
| 86 | // using URI as label if nothing else has been found. | ||
| 87 | return $this->resource->shorten() ? $this->resource->shorten() : $this->resource->getUri(); | ||
| 88 | } | ||
| 89 | |||
| 90 | private function getResourceLabel($res, $lang = '') | ||
| 91 |     { | ||
| 92 | |||
| 93 |         if ($this->clang) { | ||
| 94 | $lang = $this->clang; | ||
| 95 | } | ||
| 96 | |||
| 97 |         if ($res->label($lang) !== null) { // current language | ||
| 98 | return $res->label($lang); | ||
| 99 |         } elseif ($res->label() !== null) { // any language | ||
| 100 | return $res->label(); | ||
| 101 |         } elseif ($res->getLiteral('rdf:value', $lang) !== null) { // current language | ||
| 102 |             return $res->getLiteral('rdf:value', $lang); | ||
| 103 |         } elseif ($res->getLiteral('rdf:value') !== null) { // any language | ||
| 104 |             return $res->getLiteral('rdf:value'); | ||
| 105 | } | ||
| 106 | return null; | ||
| 107 | } | ||
| 108 | |||
| 109 | public function getUri() | ||
| 110 |     { | ||
| 111 | return $this->resource->getUri(); | ||
| 112 | } | ||
| 113 | |||
| 114 | public function getExVocab() | ||
| 115 |     { | ||
| 116 | return $this->model->guessVocabularyFromURI($this->getUri(), $this->vocab->getId()); | ||
| 117 | } | ||
| 118 | |||
| 119 | public function getVocab() | ||
| 122 | } | ||
| 123 | |||
| 124 | public function getVocabName($lang = '') | ||
| 125 |     { | ||
| 126 | |||
| 127 |         if ($this->clang) { | ||
| 128 | $lang = $this->clang; | ||
| 129 | } | ||
| 130 | |||
| 131 | // if multiple vocabularies are found, the following method will return in priority the current vocabulary of the mapping | ||
| 132 | $exvocab = $this->model->guessVocabularyFromURI($this->resource->getUri(), $this->vocab->getId()); | ||
| 133 |         if ($exvocab) { | ||
| 134 | return $exvocab->getTitle($lang); | ||
| 135 | } | ||
| 136 | |||
| 137 | // @codeCoverageIgnoreStart | ||
| 138 |         $scheme = $this->resource->get('skos:inScheme'); | ||
| 139 |         if ($scheme) { | ||
| 140 | $schemeResource = $this->model->getResourceFromUri($scheme->getUri()); | ||
| 141 |             if ($schemeResource) { | ||
| 142 | $schemaName = $this->getResourceLabel($schemeResource); | ||
| 143 |                 if ($schemaName) { | ||
| 144 | return $schemaName; | ||
| 145 | } | ||
| 146 | } | ||
| 147 | } | ||
| 148 | // got a label for the concept, but not the scheme - use the host name as scheme label | ||
| 149 | return parse_url($this->resource->getUri(), PHP_URL_HOST); | ||
| 150 | // @codeCoverageIgnoreEnd | ||
| 151 | } | ||
| 152 | |||
| 153 | public function getNotation() | ||
| 166 | } | ||
| 167 | |||
| 168 | /** | ||
| 169 | * Return the mapping as a JSKOS-compatible array. | ||
| 170 | * @return array | ||
| 171 | */ | ||
| 172 | public function asJskos($queryExVocabs = true, $lang = null, $hrefLink = null) | ||
| 253 | } | ||
| 254 | |||
| 256 | 
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.