| Conditions | 15 |
| Paths | 32 |
| Total Lines | 37 |
| Code Lines | 23 |
| Lines | 14 |
| Ratio | 37.84 % |
| 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 |
||
| 38 | public function getLabel($lang = '') |
||
| 39 | { |
||
| 40 | if ($this->clang) { |
||
| 41 | $lang = $this->clang; |
||
| 42 | } |
||
| 43 | if ($this->vocab->getConfig()->getLanguageOrder($lang)) { |
||
| 44 | View Code Duplication | foreach ($this->vocab->getConfig()->getLanguageOrder($lang) as $fallback) { |
|
| 45 | if ($this->resource->label($fallback) !== null) { |
||
| 46 | return $this->resource->label($fallback); |
||
| 47 | } |
||
| 48 | // We need to check all the labels in case one of them matches a subtag of the current language |
||
| 49 | if ($this->resource->allLiterals('skos:prefLabel')) { |
||
| 50 | foreach($this->resource->allLiterals('skos:prefLabel') as $label) { |
||
| 51 | // the label lang code is a subtag of the UI lang eg. en-GB - create a new literal with the main language |
||
| 52 | if ($label !== null && strpos($label->getLang(), $fallback . '-') === 0) { |
||
| 53 | return EasyRdf\Literal::create($label, $fallback); |
||
| 54 | } |
||
| 55 | } |
||
| 56 | } |
||
| 57 | } |
||
| 58 | } |
||
| 59 | |||
| 60 | if ($this->resource->label($lang) !== null) { // current language |
||
| 61 | return $this->resource->label($lang); |
||
| 62 | } elseif ($this->resource->label($this->vocab->getConfig()->getDefaultLanguage()) !== null) { // vocab default language |
||
| 63 | return $this->resource->label($this->vocab->getConfig()->getDefaultLanguage()); |
||
| 64 | } elseif ($this->resource->label() !== null) { // any language |
||
| 65 | return $this->resource->label(); |
||
| 66 | } elseif ($this->resource->getLiteral('rdf:value', $lang) !== null) { // current language |
||
| 67 | return $this->resource->getLiteral('rdf:value', $lang); |
||
| 68 | } elseif ($this->resource->getLiteral('rdf:value') !== null) { // any language |
||
| 69 | return $this->resource->getLiteral('rdf:value'); |
||
| 70 | } |
||
| 71 | // uri if no label is found |
||
| 72 | $label = $this->resource->shorten() ? $this->resource->shorten() : $this->getUri(); |
||
| 73 | return $label; |
||
| 74 | } |
||
| 75 | |||
| 155 |
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.