| Conditions | 7 |
| Paths | 9 |
| Total Lines | 55 |
| Code Lines | 30 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 116 | public function generateAlphabeticalListQuery($letter, $lang, $limit = null, $offset = null, $classes = null, $showDeprecated = false, $qualifier = null) |
||
| 117 | { |
||
| 118 | if ($letter == '*' || $letter == '0-9' || $letter == '!*') { |
||
| 119 | // text index cannot support special character queries, use the generic implementation for these |
||
| 120 | return parent::generateAlphabeticalListQuery($letter, $lang, $limit, $offset, $classes, $showDeprecated, $qualifier); |
||
| 121 | } |
||
| 122 | |||
| 123 | $gc = $this->graphClause; |
||
| 124 | $classes = ($classes) ? $classes : array('http://www.w3.org/2004/02/skos/core#Concept'); |
||
| 125 | $values = $this->formatValues('?type', $classes, 'uri'); |
||
| 126 | $limitandoffset = $this->formatLimitAndOffset($limit, $offset); |
||
| 127 | |||
| 128 | # make text query clause |
||
| 129 | $lcletter = mb_strtolower($letter, 'UTF-8'); // convert to lower case, UTF-8 safe |
||
| 130 | $langClause = $this->generateLangClause($lang); |
||
| 131 | $textcondPref = $this->createTextQueryCondition($letter . '*', 'skos:prefLabel', $langClause); |
||
| 132 | $textcondAlt = $this->createTextQueryCondition($letter . '*', 'skos:altLabel', $langClause); |
||
| 133 | $orderbyclause = $this->formatOrderBy("LCASE(?match)", $lang) . " STR(?s) LCASE(STR(?qualifier))"; |
||
| 134 | |||
| 135 | $qualifierClause = $qualifier ? "OPTIONAL { ?s <" . $qualifier->getURI() . "> ?qualifier }" : ""; |
||
| 136 | |||
| 137 | $filterDeprecated = ""; |
||
| 138 | if (!$showDeprecated) { |
||
| 139 | $filterDeprecated = "FILTER NOT EXISTS { ?s owl:deprecated true }"; |
||
| 140 | } |
||
| 141 | |||
| 142 | $query = <<<EOQ |
||
| 143 | SELECT DISTINCT ?s ?label ?alabel ?qualifier |
||
| 144 | WHERE { |
||
| 145 | $gc { |
||
| 146 | { |
||
| 147 | $textcondPref |
||
| 148 | FILTER(STRSTARTS(LCASE(STR(?match)), '$lcletter')) |
||
| 149 | FILTER EXISTS { ?s skos:prefLabel ?match } |
||
| 150 | BIND(?match as ?label) |
||
| 151 | } |
||
| 152 | UNION |
||
| 153 | { |
||
| 154 | $textcondAlt |
||
| 155 | FILTER(STRSTARTS(LCASE(STR(?match)), '$lcletter')) |
||
| 156 | FILTER EXISTS { ?s skos:altLabel ?match } |
||
| 157 | BIND(?match as ?alabel) |
||
| 158 | { |
||
| 159 | ?s skos:prefLabel ?label . |
||
| 160 | FILTER (langMatches(LANG(?label), '$lang')) |
||
| 161 | } |
||
| 162 | } |
||
| 163 | ?s a ?type . |
||
| 164 | $qualifierClause |
||
| 165 | $filterDeprecated |
||
| 166 | } $values |
||
| 167 | } |
||
| 168 | ORDER BY $orderbyclause $limitandoffset |
||
| 169 | EOQ; |
||
| 170 | return $query; |
||
| 171 | } |
||
| 174 |