| Conditions | 9 |
| Paths | 160 |
| Total Lines | 81 |
| Code Lines | 46 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 173 | public function asJskos($allowExternal = true, $lang = null, $hrefLink = null) |
||
| 174 | { |
||
| 175 | $propertyLabel = $this->getLabel($lang); |
||
| 176 | $propertyLang = $lang; |
||
| 177 | if (!is_string($propertyLabel)) { |
||
| 178 | $propertyLang = $propertyLabel->getLang(); |
||
| 179 | $propertyLabel = $propertyLabel->getValue(); |
||
| 180 | } |
||
| 181 | $ret = [ |
||
| 182 | // JSKOS |
||
| 183 | 'uri' => $this->source->getUri(), |
||
| 184 | 'notation' => $this->getNotation(), |
||
| 185 | 'type' => [$this->type], |
||
| 186 | 'prefLabel' => $propertyLabel, |
||
| 187 | 'from' => [ |
||
| 188 | 'memberSet' => [ |
||
| 189 | [ |
||
| 190 | 'uri' => (string) $this->source->getUri(), |
||
| 191 | ] |
||
| 192 | ] |
||
| 193 | ], |
||
| 194 | 'to' => [ |
||
| 195 | 'memberSet' => [ |
||
| 196 | [ |
||
| 197 | 'uri' => (string) $this->getUri() |
||
| 198 | ] |
||
| 199 | ] |
||
| 200 | ], |
||
| 201 | // EXTRA |
||
| 202 | 'hrefLink' => $hrefLink, // link to resource as displayed in the UI |
||
| 203 | 'lang' => $propertyLang, // TBD: could it be part of the prefLabel? |
||
| 204 | 'vocabName' => (string) $this->getVocabName(), // vocabulary as displayed in the UI |
||
| 205 | 'typeLabel' => $this->model->getText($this->type), // a text used in the UI instead of, for example, skos:closeMatch |
||
| 206 | ]; |
||
| 207 | |||
| 208 | $helpprop = $this->type . "_help"; |
||
| 209 | // see if we have a translation for the property help text |
||
| 210 | $help = $this->model->getText($helpprop); |
||
| 211 | if ($help != $helpprop) { |
||
| 212 | $ret['description'] = $help; |
||
| 213 | } |
||
| 214 | |||
| 215 | $fromScheme = $this->vocab->getDefaultConceptScheme(); |
||
| 216 | if (isset($fromScheme)) { |
||
| 217 | $ret['fromScheme'] = [ |
||
| 218 | 'uri' => (string) $fromScheme, |
||
| 219 | ]; |
||
| 220 | } |
||
| 221 | |||
| 222 | $exvocab = $this->getExvocab(); |
||
| 223 | if (isset($exvocab)) { |
||
| 224 | $ret['toScheme'] = [ |
||
| 225 | 'uri' => (string) $exvocab->getDefaultConceptScheme(), |
||
| 226 | ]; |
||
| 227 | } |
||
| 228 | |||
| 229 | $notation = $this->getNotation(); |
||
| 230 | if (isset($notation)) { |
||
| 231 | $ret['to']['memberSet'][0]['notation'] = (string) $notation; |
||
| 232 | } |
||
| 233 | |||
| 234 | $label = $this->getLabel($lang, $allowExternal); |
||
| 235 | if (isset($label)) { |
||
| 236 | if (is_string($label)) { |
||
| 237 | list($labelLang, $labelValue) = ['', $label]; |
||
| 238 | } else { |
||
| 239 | list($labelLang, $labelValue) = [$label->getLang(), $label->getValue()]; |
||
| 240 | } |
||
| 241 | // set the language of the preferred label to be whatever returned |
||
| 242 | $ret['lang'] = $labelLang; |
||
| 243 | |||
| 244 | if ($labelValue != $this->getUri()) { |
||
| 245 | // The `queryLabel()` method above will fallback to returning the URI |
||
| 246 | // if no label was found. We don't want that here. |
||
| 247 | $ret['to']['memberSet'][0]['prefLabel'] = [ |
||
| 248 | $labelLang => $labelValue, |
||
| 249 | ]; |
||
| 250 | } |
||
| 251 | } |
||
| 252 | |||
| 253 | return $ret; |
||
| 254 | } |
||
| 257 |