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