| Total Complexity | 49 | 
| Total Lines | 177 | 
| Duplicated Lines | 0 % | 
| Changes | 1 | ||
| Bugs | 0 | Features | 0 | 
Complex classes like ConceptPropertyValue often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use ConceptPropertyValue, and based on these observations, apply Extract Interface, too.
| 1 | <?php | ||
| 6 | class ConceptPropertyValue extends VocabularyDataObject | ||
| 7 | { | ||
| 8 | /** submembers */ | ||
| 9 | private $submembers; | ||
| 10 | /** property type */ | ||
| 11 | private $type; | ||
| 12 | /** content language */ | ||
| 13 | private $clang; | ||
| 14 | /** whether the property value is external w.r.t. to the subject resource */ | ||
| 15 | private $external; | ||
| 16 | |||
| 17 | public function __construct($model, $vocab, $resource, $prop, $clang = '') | ||
| 30 | } | ||
| 31 | } | ||
| 32 | } | ||
| 33 | |||
| 34 | public function __toString() | ||
| 35 |     { | ||
| 36 | return is_string($this->getLabel()) ? $this->getLabel() : $this->getLabel()->getValue(); | ||
|  | |||
| 37 | } | ||
| 38 | |||
| 39 | public function getLang() | ||
| 42 | } | ||
| 43 | |||
| 44 | public function getSortKey() | ||
| 47 | } | ||
| 48 | |||
| 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 | } | ||
| 97 | |||
| 98 | public function getType() | ||
| 99 |     { | ||
| 100 | return $this->type; | ||
| 101 | } | ||
| 102 | |||
| 103 | public function getUri() | ||
| 106 | } | ||
| 107 | |||
| 108 | public function getExVocab() | ||
| 109 |     { | ||
| 110 | return $this->model->guessVocabularyFromURI($this->getUri(), $this->vocab->getId()); | ||
| 111 | } | ||
| 112 | |||
| 113 | public function getVocab() | ||
| 114 |     { | ||
| 115 | return $this->vocab; | ||
| 116 | } | ||
| 117 | |||
| 118 | public function getVocabName() | ||
| 119 |     { | ||
| 120 | return $this->vocab->getShortName(); | ||
| 121 | } | ||
| 122 | |||
| 123 | public function addSubMember($member, $lang = '') | ||
| 124 |     { | ||
| 125 | $label = $member->getLabel($lang) ? $member->getLabel($lang) : $member->getLabel(); | ||
| 126 | $this->submembers[$label->getValue()] = $member; | ||
| 127 | $this->sortSubMembers(); | ||
| 128 | } | ||
| 129 | |||
| 130 | public function getSubMembers() | ||
| 131 |     { | ||
| 132 |         if (empty($this->submembers)) { | ||
| 133 | return null; | ||
| 134 | } | ||
| 135 | |||
| 136 | return $this->submembers; | ||
| 137 | } | ||
| 138 | |||
| 139 | private function sortSubMembers() | ||
| 143 | } | ||
| 144 | |||
| 145 | } | ||
| 146 | |||
| 147 | public function isExternal() | ||
| 150 | } | ||
| 151 | |||
| 152 | public function getNotation() | ||
| 156 | } | ||
| 157 | |||
| 158 | } | ||
| 159 | |||
| 160 | public function isReified() | ||
| 163 | } | ||
| 164 | |||
| 165 | public function getReifiedPropertyValues() | ||
| 166 |     { | ||
| 167 | $ret = array(); | ||
| 183 | } | ||
| 184 | |||
| 186 |