Conditions | 9 |
Paths | 160 |
Total Lines | 81 |
Code Lines | 46 |
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 |
||
172 | public function asJskos($queryExVocabs = true, $lang = null, $hrefLink = null) |
||
173 | { |
||
174 | $propertyLabel = $this->getLabel($lang, $queryExVocabs); |
||
175 | $propertyLang = $lang; |
||
176 | if (!is_string($propertyLabel)) { |
||
177 | $propertyLang = $propertyLabel->getLang(); |
||
178 | $propertyLabel = $propertyLabel->getValue(); |
||
179 | } |
||
180 | $ret = [ |
||
181 | // JSKOS |
||
182 | 'uri' => $this->source->getUri(), |
||
183 | 'notation' => $this->getNotation(), |
||
184 | 'type' => [$this->type], |
||
185 | 'prefLabel' => $propertyLabel, |
||
186 | 'from' => [ |
||
187 | 'memberSet' => [ |
||
188 | [ |
||
189 | 'uri' => (string) $this->source->getUri(), |
||
190 | ] |
||
191 | ] |
||
192 | ], |
||
193 | 'to' => [ |
||
194 | 'memberSet' => [ |
||
195 | [ |
||
196 | 'uri' => (string) $this->getUri() |
||
197 | ] |
||
198 | ] |
||
199 | ], |
||
200 | // EXTRA |
||
201 | 'hrefLink' => $hrefLink, // link to resource as displayed in the UI |
||
202 | 'lang' => $propertyLang, // TBD: could it be part of the prefLabel? |
||
203 | 'vocabName' => (string) $this->getVocabName(), // vocabulary as displayed in the UI |
||
204 | 'typeLabel' => $this->model->getText($this->type), // a text used in the UI instead of, for example, skos:closeMatch |
||
205 | ]; |
||
206 | |||
207 | $helpprop = $this->type . "_help"; |
||
208 | // see if we have a translation for the property help text |
||
209 | $help = $this->model->getText($helpprop); |
||
210 | if ($help != $helpprop) { |
||
211 | $ret['description'] = $help; |
||
212 | } |
||
213 | |||
214 | $fromScheme = $this->vocab->getDefaultConceptScheme(); |
||
215 | if (isset($fromScheme)) { |
||
216 | $ret['fromScheme'] = [ |
||
217 | 'uri' => (string) $fromScheme, |
||
218 | ]; |
||
219 | } |
||
220 | |||
221 | $exvocab = $this->getExvocab(); |
||
222 | if (isset($exvocab)) { |
||
223 | $ret['toScheme'] = [ |
||
224 | 'uri' => (string) $exvocab->getDefaultConceptScheme(), |
||
225 | ]; |
||
226 | } |
||
227 | |||
228 | $notation = $this->getNotation(); |
||
229 | if (isset($notation)) { |
||
230 | $ret['to']['memberSet'][0]['notation'] = (string) $notation; |
||
231 | } |
||
232 | |||
233 | $label = $this->getLabel($lang, $queryExVocabs); |
||
234 | if (isset($label)) { |
||
235 | if (is_string($label)) { |
||
236 | list($labelLang, $labelValue) = ['', $label]; |
||
237 | } else { |
||
238 | list($labelLang, $labelValue) = [$label->getLang(), $label->getValue()]; |
||
239 | } |
||
240 | // set the language of the preferred label to be whatever returned |
||
241 | $ret['lang'] = $labelLang; |
||
242 | |||
243 | if ($labelValue != $this->getUri()) { |
||
244 | // The `queryLabel()` method above will fallback to returning the URI |
||
245 | // if no label was found. We don't want that here. |
||
246 | $ret['to']['memberSet'][0]['prefLabel'] = [ |
||
247 | $labelLang => $labelValue, |
||
248 | ]; |
||
249 | } |
||
250 | } |
||
251 | |||
252 | return $ret; |
||
253 | } |
||
256 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.