| Conditions | 18 |
| Paths | 52 |
| Total Lines | 47 |
| Code Lines | 27 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 49 | public function getLabel($lang = '', $fallbackToUri = 'uri', $allowExternal = true) |
||
| 50 | { |
||
| 51 | if ($this->clang) { |
||
| 52 | $lang = $this->clang; |
||
| 53 | } |
||
| 54 | if ($this->vocab->getConfig()->getLanguageOrder($lang)) { |
||
| 55 | foreach ($this->vocab->getConfig()->getLanguageOrder($lang) as $fallback) { |
||
| 56 | if ($this->resource->label($fallback) !== null) { |
||
| 57 | return $this->resource->label($fallback); |
||
| 58 | } |
||
| 59 | // We need to check all the labels in case one of them matches a subtag of the current language |
||
| 60 | if ($this->resource->allLiterals('skos:prefLabel')) { |
||
| 61 | foreach ($this->resource->allLiterals('skos:prefLabel') as $label) { |
||
| 62 | // the label lang code is a subtag of the UI lang eg. en-GB - create a new literal with the main language |
||
| 63 | if ($label !== null && strpos($label->getLang(), $fallback . '-') === 0) { |
||
| 64 | return EasyRdf\Literal::create($label, $fallback); |
||
| 65 | } |
||
| 66 | } |
||
| 67 | } |
||
| 68 | } |
||
| 69 | } |
||
| 70 | |||
| 71 | if ($this->resource->label($lang) !== null) { // current language |
||
| 72 | return $this->resource->label($lang); |
||
| 73 | } elseif ($this->resource->label($this->vocab->getConfig()->getDefaultLanguage()) !== null) { // vocab default language |
||
| 74 | return $this->resource->label($this->vocab->getConfig()->getDefaultLanguage()); |
||
| 75 | } elseif ($this->resource->label() !== null) { // any language |
||
| 76 | return $this->resource->label(); |
||
| 77 | } elseif ($this->resource->getLiteral('rdf:value', $lang) !== null) { // current language |
||
| 78 | return $this->resource->getLiteral('rdf:value', $lang); |
||
| 79 | } elseif ($this->resource->getLiteral('rdf:value') !== null) { // any language |
||
| 80 | return $this->resource->getLiteral('rdf:value'); |
||
| 81 | } |
||
| 82 | |||
| 83 | // see if we can find a label in another vocabulary known by the skosmos instance |
||
| 84 | if ($allowExternal) { |
||
| 85 | $label = $this->getExternalLabel($this->vocab, $this->getUri(), $lang); |
||
| 86 | if ($label) { |
||
| 87 | return $label; |
||
| 88 | } |
||
| 89 | } |
||
| 90 | |||
| 91 | if ($fallbackToUri == 'uri') { |
||
| 92 | // return uri if no label is found |
||
| 93 | return $this->resource->shorten() ? $this->resource->shorten() : $this->getUri(); |
||
| 94 | } |
||
| 95 | return null; |
||
| 96 | } |
||
| 186 |