Conditions | 5 |
Paths | 16 |
Total Lines | 71 |
Code Lines | 24 |
Lines | 0 |
Ratio | 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 |
||
70 | # make text query clauses |
||
71 | $textcond = $this->createTextQueryCondition($term, '?prop', $search_lang); |
||
72 | |||
73 | if ($this->isDefaultEndpoint()) { |
||
74 | # if doing a global search, we should target the union graph instead of a specific graph |
||
75 | $textcond = "GRAPH <urn:x-arq:UnionGraph> { $textcond }"; |
||
76 | } |
||
77 | |||
78 | return $textcond; |
||
79 | } |
||
80 | |||
81 | /** |
||
82 | * Generates the jena-text-specific sparql query used for rendering the alphabetical index. |
||
83 | * @param string $letter the letter (or special class) to search for |
||
84 | * @param string $lang language of labels |
||
85 | * @param integer $limit limits the amount of results |
||
86 | * @param integer $offset offsets the result set |
||
87 | * @param array $classes |
||
88 | * @return string sparql query |
||
89 | */ |
||
90 | |||
91 | public function generateAlphabeticalListQuery($letter, $lang, $limit = null, $offset = null, $classes = null) |
||
92 | { |
||
93 | if ($letter == '*' || $letter == '0-9' || $letter == '!*') { |
||
94 | // text index cannot support special character queries, use the generic implementation for these |
||
95 | return parent::generateAlphabeticalListQuery($letter, $lang, $limit, $offset, $classes); |
||
96 | } |
||
97 | |||
98 | $gc = $this->graphClause; |
||
99 | $classes = ($classes) ? $classes : array('http://www.w3.org/2004/02/skos/core#Concept'); |
||
100 | $values = $this->formatValues('?type', $classes, 'uri'); |
||
101 | $limitandoffset = $this->formatLimitAndOffset($limit, $offset); |
||
102 | |||
103 | # make text query clause |
||
104 | $lcletter = mb_strtolower($letter, 'UTF-8'); // convert to lower case, UTF-8 safe |
||
105 | $textcond_pref = $this->createTextQueryCondition($letter . '*', 'skos:prefLabel', $lang); |
||
106 | $textcond_alt = $this->createTextQueryCondition($letter . '*', 'skos:altLabel', $lang); |
||
107 | |||
108 | $query = <<<EOQ |
||
109 | SELECT DISTINCT ?s ?label ?alabel |
||
110 | WHERE { |
||
111 | $gc { |
||
112 | { |
||
113 | $textcond_pref |
||
114 | FILTER(STRSTARTS(LCASE(STR(?match)), '$lcletter')) |
||
115 | BIND(?match as ?label) |
||
116 | } |
||
117 | UNION |
||
118 | { |
||
119 | $textcond_alt |
||
120 | FILTER(STRSTARTS(LCASE(STR(?match)), '$lcletter')) |
||
121 | BIND(?match as ?alabel) |
||
122 | { |
||
123 | ?s skos:prefLabel ?label . |
||
124 | FILTER (langMatches(LANG(?label), '$lang')) |
||
125 | } |
||
126 | } |
||
127 | ?s a ?type . |
||
128 | FILTER NOT EXISTS { ?s owl:deprecated true } |
||
129 | } $values |
||
130 | } |
||
131 | ORDER BY LCASE(?match) $limitandoffset |
||
132 | EOQ; |
||
133 | return $query; |
||
134 | } |
||
135 | |||
136 | } |
||
137 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.