| Conditions | 73 |
| Paths | > 20000 |
| Total Lines | 207 |
| Code Lines | 142 |
| 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 |
||
| 59 | function processNode($n, $ct, $level) { |
||
| 60 | if ($n['tag']=='cdata' || $n['tag']=='comment') return null; /* patch by tobyink */ |
||
| 61 | $ts_added = 0; |
||
| 62 | /* step 1 */ |
||
| 63 | $lct = array(); |
||
| 64 | $lct['prev_s'] = $this->v('prev_s', $this->v('p_s', '', $ct), $ct); |
||
| 65 | $lct['recurse'] = 1; |
||
| 66 | $lct['skip'] = 0; |
||
| 67 | $lct['new_s'] = ''; |
||
| 68 | $lct['cur_o_res'] = ''; |
||
| 69 | $lct['inco_ts'] = array(); |
||
| 70 | $lct['base'] = $ct['base']; |
||
| 71 | //$lct['base'] = $this->v('xml:base', $ct['base'], $n['a']); |
||
| 72 | /* step 2 */ |
||
| 73 | $lct['ns'] = array_merge($ct['ns'], $this->v('xmlns', array(), $n['a'])); |
||
| 74 | /* step 3 */ |
||
| 75 | $lct['lang'] = $this->v('xml:lang', $ct['lang'], $n['a']); |
||
| 76 | /* step 4 */ |
||
| 77 | $rel_uris = $this->getAttributeURIs($n, $ct, $lct, 'rel'); |
||
| 78 | $rev_uris = $this->getAttributeURIs($n, $ct, $lct, 'rev'); |
||
| 79 | if (!$rel_uris && !$rev_uris) { |
||
| 80 | foreach (array('about', 'src', 'resource', 'href') as $attr) { |
||
| 81 | if (isset($n['a'][$attr]) && (list($uri, $sub_v) = $this->xURI($n['a'][$attr], $lct['base'], $lct['ns'], '', $lct)) && $uri) { |
||
| 82 | $lct['new_s'] = $uri; |
||
| 83 | break; |
||
| 84 | } |
||
| 85 | } |
||
| 86 | if (!$lct['new_s']) { |
||
| 87 | if (preg_match('/(head|body)/i', $n['tag'])) { |
||
| 88 | $lct['new_s'] = $lct['base']; |
||
| 89 | } |
||
| 90 | elseif ($this->getAttributeURIs($n, $ct, $lct, 'typeof')) { |
||
| 91 | $lct['new_s'] = $this->createBnodeID(); |
||
| 92 | } |
||
| 93 | elseif ($ct['p_o']) { |
||
| 94 | $lct['new_s'] = $ct['p_o']; |
||
| 95 | //$lct['skip'] = 1; |
||
| 96 | if(!isset($n['a']['property'])) $lct['skip'] = 1;/* patch by masaka */ |
||
| 97 | } |
||
| 98 | } |
||
| 99 | } |
||
| 100 | /* step 5 */ |
||
| 101 | else { |
||
| 102 | foreach (array('about', 'src') as $attr) { |
||
| 103 | if (isset($n['a'][$attr]) && (list($uri, $sub_v) = $this->xURI($n['a'][$attr], $lct['base'], $lct['ns'], '', $lct)) && $uri) { |
||
| 104 | $lct['new_s'] = $uri; |
||
| 105 | break; |
||
| 106 | } |
||
| 107 | } |
||
| 108 | if (!$lct['new_s']) { |
||
| 109 | if (preg_match('/(head|body)/i', $n['tag'])) { |
||
| 110 | $lct['new_s'] = $lct['base']; |
||
| 111 | } |
||
| 112 | elseif ($this->getAttributeURIs($n, $ct, $lct, 'typeof')) { |
||
| 113 | $lct['new_s'] = $this->createBnodeID(); |
||
| 114 | } |
||
| 115 | elseif ($ct['p_o']) { |
||
| 116 | $lct['new_s'] = $ct['p_o']; |
||
| 117 | } |
||
| 118 | } |
||
| 119 | foreach (array('resource', 'href') as $attr) { |
||
| 120 | if (isset($n['a'][$attr]) && (list($uri, $sub_v) = $this->xURI($n['a'][$attr], $lct['base'], $lct['ns'], '', $lct)) && $uri) { |
||
| 121 | $lct['cur_o_res'] = $uri; |
||
| 122 | break; |
||
| 123 | } |
||
| 124 | } |
||
| 125 | } |
||
| 126 | /* step 6 */ |
||
| 127 | if ($lct['new_s']) { |
||
| 128 | if ($uris = $this->getAttributeURIs($n, $ct, $lct, 'typeof')) { |
||
| 129 | foreach ($uris as $uri) { |
||
| 130 | $this->addT(array( |
||
| 131 | 's' => $lct['new_s'], |
||
| 132 | 's_type' => preg_match('/^\_\:/', $lct['new_s']) ? 'bnode' : 'uri', |
||
| 133 | 'p' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', |
||
| 134 | 'o' => $uri, |
||
| 135 | 'o_type' => 'uri', |
||
| 136 | 'o_lang' => '', |
||
| 137 | 'o_datatype' => '', |
||
| 138 | )); |
||
| 139 | $ts_added = 1; |
||
| 140 | } |
||
| 141 | } |
||
| 142 | /* step 7 */ |
||
| 143 | if ($lct['cur_o_res']) { |
||
| 144 | if ($rel_uris) { |
||
| 145 | foreach ($rel_uris as $uri) { |
||
| 146 | $this->addT(array( |
||
| 147 | 's' => $lct['new_s'], |
||
| 148 | 's_type' => preg_match('/^\_\:/', $lct['new_s']) ? 'bnode' : 'uri', |
||
| 149 | 'p' => $uri, |
||
| 150 | 'o' => $lct['cur_o_res'], |
||
| 151 | 'o_type' => preg_match('/^\_\:/', $lct['cur_o_res']) ? 'bnode' : 'uri', |
||
| 152 | 'o_lang' => '', |
||
| 153 | 'o_datatype' => '', |
||
| 154 | )); |
||
| 155 | $ts_added = 1; |
||
| 156 | } |
||
| 157 | } |
||
| 158 | if ($rev_uris) { |
||
| 159 | foreach ($rev_uris as $uri) { |
||
| 160 | $this->addT(array( |
||
| 161 | 's' => $lct['cur_o_res'], |
||
| 162 | 's_type' => preg_match('/^\_\:/', $lct['cur_o_res']) ? 'bnode' : 'uri', |
||
| 163 | 'p' => $uri, |
||
| 164 | 'o' => $lct['new_s'], |
||
| 165 | 'o_type' => preg_match('/^\_\:/', $lct['new_s']) ? 'bnode' : 'uri', |
||
| 166 | 'o_lang' => '', |
||
| 167 | 'o_datatype' => '', |
||
| 168 | )); |
||
| 169 | $ts_added = 1; |
||
| 170 | } |
||
| 171 | } |
||
| 172 | } |
||
| 173 | } |
||
| 174 | /* step 8 */ |
||
| 175 | if (!$lct['cur_o_res']) { |
||
| 176 | if ($rel_uris || $rev_uris) { |
||
| 177 | $lct['cur_o_res'] = $this->createBnodeID(); |
||
| 178 | foreach ($rel_uris as $uri) { |
||
| 179 | $lct['inco_ts'][] = array('p' => $uri, 'dir' => 'fwd'); |
||
| 180 | } |
||
| 181 | foreach ($rev_uris as $uri) { |
||
| 182 | $lct['inco_ts'][] = array('p' => $uri, 'dir' => 'rev'); |
||
| 183 | } |
||
| 184 | } |
||
| 185 | } |
||
| 186 | /* step 10 */ |
||
| 187 | if (!$lct['skip'] && ($new_s = $lct['new_s'])) { |
||
| 188 | //if ($new_s = $lct['new_s']) { |
||
| 189 | if ($uris = $this->getAttributeURIs($n, $ct, $lct, 'property')) { |
||
| 190 | foreach ($uris as $uri) { |
||
| 191 | $lct['cur_o_lit'] = $this->getCurrentObjectLiteral($n, $lct, $ct); |
||
| 192 | $this->addT(array( |
||
| 193 | 's' => $lct['new_s'], |
||
| 194 | 's_type' => preg_match('/^\_\:/', $lct['new_s']) ? 'bnode' : 'uri', |
||
| 195 | 'p' => $uri, |
||
| 196 | 'o' => $lct['cur_o_lit']['value'], |
||
| 197 | 'o_type' => 'literal', |
||
| 198 | 'o_lang' => $lct['cur_o_lit']['lang'], |
||
| 199 | 'o_datatype' => $lct['cur_o_lit']['datatype'], |
||
| 200 | )); |
||
| 201 | $ts_added = 1; |
||
| 202 | if ($lct['cur_o_lit']['datatype'] == 'http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral') { |
||
| 203 | $lct['recurse'] = 0; |
||
| 204 | } |
||
| 205 | } |
||
| 206 | } |
||
| 207 | } |
||
| 208 | /* step 11 (10) */ |
||
| 209 | $complete_triples = 0; |
||
| 210 | if ($lct['recurse']) { |
||
| 211 | if ($lct['skip']) { |
||
| 212 | $new_ct = array_merge($ct, array('base' => $lct['base'], 'lang' => $lct['lang'], 'ns' => $lct['ns'])); |
||
| 213 | } |
||
| 214 | else { |
||
| 215 | $new_ct = array( |
||
| 216 | 'base' => $lct['base'], |
||
| 217 | 'p_s' => $lct['new_s'] ? $lct['new_s'] : $ct['p_s'], |
||
| 218 | 'p_o' => $lct['cur_o_res'] ? $lct['cur_o_res'] : ($lct['new_s'] ? $lct['new_s'] : $ct['p_s']), |
||
| 219 | 'ns' => $lct['ns'], |
||
| 220 | 'inco_ts' => $lct['inco_ts'], |
||
| 221 | 'lang' => $lct['lang'] |
||
| 222 | ); |
||
| 223 | } |
||
| 224 | $sub_nodes = $this->getSubNodes($n); |
||
| 225 | foreach ($sub_nodes as $sub_node) { |
||
| 226 | if ($this->processNode($sub_node, $new_ct, $level+1)) { |
||
| 227 | $complete_triples = 1; |
||
| 228 | } |
||
| 229 | } |
||
| 230 | } |
||
| 231 | /* step 12 (11) */ |
||
| 232 | $other = 0; |
||
| 233 | if ($ts_added || $complete_triples || ($lct['new_s'] && !preg_match('/^\_\:/', $lct['new_s'])) || ($other == 1)) { |
||
| 234 | //if (!$lct['skip'] && ($complete_triples || ($lct['new_s'] && !preg_match('/^\_\:/', $lct['new_s'])))) { |
||
| 235 | foreach ($ct['inco_ts'] as $inco_t) { |
||
| 236 | if ($inco_t['dir'] == 'fwd') { |
||
| 237 | $this->addT(array( |
||
| 238 | 's' => $ct['p_s'], |
||
| 239 | 's_type' => preg_match('/^\_\:/', $ct['p_s']) ? 'bnode' : 'uri', |
||
| 240 | 'p' => $inco_t['p'], |
||
| 241 | 'o' => $lct['new_s'], |
||
| 242 | 'o_type' => preg_match('/^\_\:/', $lct['new_s']) ? 'bnode' : 'uri', |
||
| 243 | 'o_lang' => '', |
||
| 244 | 'o_datatype' => '', |
||
| 245 | )); |
||
| 246 | } |
||
| 247 | elseif ($inco_t['dir'] == 'rev') { |
||
| 248 | $this->addT(array( |
||
| 249 | 's' => $lct['new_s'], |
||
| 250 | 's_type' => preg_match('/^\_\:/', $lct['new_s']) ? 'bnode' : 'uri', |
||
| 251 | 'p' => $inco_t['p'], |
||
| 252 | 'o' => $ct['p_s'], |
||
| 253 | 'o_type' => preg_match('/^\_\:/', $ct['p_s']) ? 'bnode' : 'uri', |
||
| 254 | 'o_lang' => '', |
||
| 255 | 'o_datatype' => '', |
||
| 256 | )); |
||
| 257 | } |
||
| 258 | } |
||
| 259 | } |
||
| 260 | /* step 13 (12) (result flag) */ |
||
| 261 | if ($ts_added) return 1; |
||
| 262 | if ($lct['new_s'] && !preg_match('/^\_\:/', $lct['new_s'])) return 1; |
||
| 263 | if ($complete_triples) return 1; |
||
| 264 | return 0; |
||
| 265 | } |
||
| 266 | |||
| 390 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.