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