| Conditions | 31 |
| Paths | > 20000 |
| Total Lines | 144 |
| Code Lines | 106 |
| 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 | function processNode($n, $ct) { |
||
| 71 | /* context */ |
||
| 72 | //$ct['lang'] = $this->v('xml:lang', $ct['lang'], $n['a']); |
||
| 73 | $ct['lang'] = ''; |
||
| 74 | $ct['prop_uris'] = $this->getPropertyURIs($n, $ct); |
||
| 75 | $ct['prev_res'] = $ct['cur_res']; |
||
| 76 | $ct['cur_res'] = $this->getCurrentResourceURI($n, $ct); |
||
| 77 | $ct['cur_obj_id'] = $this->getCurrentObjectID($n, $ct); |
||
| 78 | $ct['cur_obj_literal'] = $this->getCurrentObjectLiteral($n, $ct); |
||
| 79 | /* triple production (http://research.talis.com/2005/erdf/wiki/Main/SummaryOfTripleProductionRules) */ |
||
| 80 | foreach ($ct['prop_uris'] as $type => $uris) { |
||
| 81 | foreach ($uris as $uri) { |
||
| 82 | $rdf_type = preg_match('/^ /', $uri) ? 1 : 0; |
||
| 83 | /* meta + name */ |
||
| 84 | if (($type == 'name') && ($n['tag'] == 'meta')) { |
||
| 85 | $t = array( |
||
| 86 | 's' => $ct['cur_res'], |
||
| 87 | 's_type' => 'uri', |
||
| 88 | 'p' => $uri, |
||
| 89 | 'o' => $ct['cur_obj_literal']['value'], |
||
| 90 | 'o_type' => 'literal', |
||
| 91 | 'o_lang' => $ct['cur_obj_literal']['datatype'] ? '' : $ct['cur_obj_literal']['lang'], |
||
| 92 | 'o_datatype' => $ct['cur_obj_literal']['datatype'], |
||
| 93 | ); |
||
| 94 | $this->addT($t); |
||
| 95 | } |
||
| 96 | /* class */ |
||
| 97 | if ($type == 'class') { |
||
| 98 | if ($rdf_type) { |
||
| 99 | $s = $this->v('href uri', $ct['cur_res'], $n['a']); |
||
| 100 | $s = $this->v('src uri', $s, $n['a']); |
||
| 101 | $t = array( |
||
| 102 | 's' => $s, |
||
| 103 | 's_type' => 'uri', |
||
| 104 | 'p' => $ct['ns']['rdf'] . 'type', |
||
| 105 | 'o' => trim($uri), |
||
| 106 | 'o_type' => 'uri', |
||
| 107 | 'o_lang' => '', |
||
| 108 | 'o_datatype' => '', |
||
| 109 | ); |
||
| 110 | } |
||
| 111 | elseif (isset($n['a']['id'])) {/* used as object */ |
||
| 112 | $t = array( |
||
| 113 | 's' => $ct['prev_res'], |
||
| 114 | 's_type' => 'uri', |
||
| 115 | 'p' => $uri, |
||
| 116 | 'o' => $ct['cur_res'], |
||
| 117 | 'o_type' => 'uri', |
||
| 118 | 'o_lang' => '', |
||
| 119 | 'o_datatype' => '', |
||
| 120 | ); |
||
| 121 | } |
||
| 122 | else { |
||
| 123 | $t = array( |
||
| 124 | 's' => $ct['cur_res'], |
||
| 125 | 's_type' => 'uri', |
||
| 126 | 'p' => $uri, |
||
| 127 | 'o' => $ct['cur_obj_literal']['value'], |
||
| 128 | 'o_type' => 'literal', |
||
| 129 | 'o_lang' => $ct['cur_obj_literal']['datatype'] ? '' : $ct['cur_obj_literal']['lang'], |
||
| 130 | 'o_datatype' => $ct['cur_obj_literal']['datatype'], |
||
| 131 | ); |
||
| 132 | if (($o = $this->v('src uri', '', $n['a'])) || ($o = $this->v('href uri', '', $n['a']))) { |
||
| 133 | if (!$ct['prop_uris']['rel'] && !$ct['prop_uris']['rev']) { |
||
| 134 | $t['o'] = $o; |
||
| 135 | $t['o_type'] = 'uri'; |
||
| 136 | $t['o_lang'] = ''; |
||
| 137 | $t['o_datatype'] = ''; |
||
| 138 | } |
||
| 139 | } |
||
| 140 | } |
||
| 141 | $this->addT($t); |
||
| 142 | } |
||
| 143 | /* rel */ |
||
| 144 | if ($type == 'rel') { |
||
| 145 | if (($o = $this->v('src uri', '', $n['a'])) || ($o = $this->v('href uri', '', $n['a']))) { |
||
| 146 | $t = array( |
||
| 147 | 's' => $ct['cur_res'], |
||
| 148 | 's_type' => 'uri', |
||
| 149 | 'p' => $uri, |
||
| 150 | 'o' => $o, |
||
| 151 | 'o_type' => 'uri', |
||
| 152 | 'o_lang' => '', |
||
| 153 | 'o_datatype' => '', |
||
| 154 | ); |
||
| 155 | $this->addT($t); |
||
| 156 | } |
||
| 157 | } |
||
| 158 | /* rev */ |
||
| 159 | if ($type == 'rev') { |
||
| 160 | if (($s = $this->v('src uri', '', $n['a'])) || ($s = $this->v('href uri', '', $n['a']))) { |
||
| 161 | $t = array( |
||
| 162 | 's' => $s, |
||
| 163 | 's_type' => 'uri', |
||
| 164 | 'p' => $uri, |
||
| 165 | 'o' => $ct['cur_res'], |
||
| 166 | 'o_type' => 'uri', |
||
| 167 | 'o_lang' => '', |
||
| 168 | 'o_datatype' => '', |
||
| 169 | ); |
||
| 170 | $this->addT($t); |
||
| 171 | } |
||
| 172 | } |
||
| 173 | } |
||
| 174 | } |
||
| 175 | /* imgs */ |
||
| 176 | if ($n['tag'] == 'img') { |
||
| 177 | if (($s = $this->v('src uri', '', $n['a'])) && $ct['cur_obj_literal']['value']) { |
||
| 178 | $t = array( |
||
| 179 | 's' => $s, |
||
| 180 | 's_type' => 'uri', |
||
| 181 | 'p' => $ct['ns']['rdfs'] . 'label', |
||
| 182 | 'o' => $ct['cur_obj_literal']['value'], |
||
| 183 | 'o_type' => 'literal', |
||
| 184 | 'o_lang' => $ct['cur_obj_literal']['datatype'] ? '' : $ct['cur_obj_literal']['lang'], |
||
| 185 | 'o_datatype' => $ct['cur_obj_literal']['datatype'], |
||
| 186 | ); |
||
| 187 | $this->addT($t); |
||
| 188 | } |
||
| 189 | } |
||
| 190 | /* anchors */ |
||
| 191 | if ($n['tag'] == 'a') { |
||
| 192 | if (($s = $this->v('href uri', '', $n['a'])) && $ct['cur_obj_literal']['value']) { |
||
| 193 | $t = array( |
||
| 194 | 's' => $s, |
||
| 195 | 's_type' => 'uri', |
||
| 196 | 'p' => $ct['ns']['rdfs'] . 'label', |
||
| 197 | 'o' => $ct['cur_obj_literal']['value'], |
||
| 198 | 'o_type' => 'literal', |
||
| 199 | 'o_lang' => $ct['cur_obj_literal']['datatype'] ? '' : $ct['cur_obj_literal']['lang'], |
||
| 200 | 'o_datatype' => $ct['cur_obj_literal']['datatype'], |
||
| 201 | ); |
||
| 202 | $this->addT($t); |
||
| 203 | } |
||
| 204 | } |
||
| 205 | /* recurse */ |
||
| 206 | if ($n['tag'] == 'a') { |
||
| 207 | $ct['cur_res'] = $ct['cur_obj_id']; |
||
| 208 | } |
||
| 209 | $sub_nodes = $this->getSubNodes($n); |
||
| 210 | foreach ($sub_nodes as $sub_node) { |
||
| 211 | $this->processNode($sub_node, $ct); |
||
| 212 | } |
||
| 213 | } |
||
| 214 | |||
| 289 |
This checks looks for assignemnts to variables using the
list(...)function, where not all assigned variables are subsequently used.Consider the following code example.
Only the variables
$aand$care used. There was no need to assign$b.Instead, the list call could have been.