Code Duplication    Length = 12-14 lines in 2 locations

model/Concept.php 1 location

@@ 111-122 (lines=12) @@
108
     */
109
    public function getLabel()
110
    {
111
        foreach ($this->vocab->getConfig()->getLanguageOrder($this->clang) as $fallback) {
112
            if ($this->resource->label($fallback) !== null) {
113
                return $this->resource->label($fallback);
114
            }
115
            // We need to check all the labels in case one of them matches a subtag of the current language
116
            foreach($this->resource->allLiterals('skos:prefLabel') as $label) {
117
                // the label lang code is a subtag of the UI lang eg. en-GB - create a new literal with the main language
118
                if ($label !== null && strpos($label->getLang(), $fallback . '-') === 0) {
119
                    return EasyRdf\Literal::create($label, $fallback);
120
                }
121
            }
122
        }
123
124
        // Last resort: label in any language, including literal with empty language tag
125
        $label = $this->resource->label();

model/ConceptPropertyValue.php 1 location

@@ 44-57 (lines=14) @@
41
            $lang = $this->clang;
42
        }
43
        if ($this->vocab->getConfig()->getLanguageOrder($lang)) {
44
            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